Jump to content

gebeer

Members
  • Posts

    1,559
  • Joined

  • Last visited

  • Days Won

    49

Everything posted by gebeer

  1. Hello, I'm trying to add a custom description to my formfield $serverField = $modules->get("InputfieldText"); $serverField->label = "Server Name"; $serverField->attr("id+name","servername"); $serverField->attr("value",$prefillServer); $serverField->attr("class","form-control"); $serverField->description("description","Desc");// need right syntax here. Or is the method missing $serverForm->append($serverField); I get an error: Method InputfieldText::description does not exist I looked at InputfieldText.module and there is no method for adding a description. Shouldn't there be one? Couldn't find anything in the API cheatsheet that would let me do that. How would I then go about adding a description to a form field?
  2. no swipe keyboard? Mine is also auto correcting and garbling things
  3. Thank you Soma, now I got you. I moved $serverads = $pages->find("template=advertisement, ad_server={$serverId}"); before $serverpage->delete() And now everything is working
  4. @Soma I already checked that page object for second page is still there after I delete first page. They are independent from another and $serverID is defined before the other stuff and is not related to the first page that gets deleted. $serverpage and $serverad live under different parents in the tree and both never have children.
  5. Thanks for that hint. But no subpages. I also tried $pages->delete($serverad). Same result. EDIT: and $pages->delete($serverad, true)
  6. Nice guide if you want to develop on a physical server. A year ago or so I switched to developing on virtual servers set up with vagrant. They're a breeze to setup and you can carry them with you wherever you go. Recently I discovered protobox which makes it quite easy to setup virtual machines with preinstalled processwire, wordpress or whatever else.
  7. Hi, I want to delete 2 pages with $page->delete() after one another . But only one of the pages gets deleted. My code $serverpage = $pages->get($serverId); if ($action == "delete") { if ($serverpage->id) { $serverpage->delete(); //When I comment this out, $serverad further down gets deleted //if ads for that server exist, delete them $serverads = $pages->find("template=advertisement, ad_server={$serverId}"); if (count($serverads) != 0) { foreach ($serverads as $serverad) { if ($serverad->id) $serverad->delete(); //does not get deleted when $serverpage->delete() above executes. } $serverout .= "<div class='alert alert-success' role='alert'>All Ads for the server deleted.</div>"; } $serverout .= "<div class='alert alert-success' role='alert'>Server successfully deleted.</div>"; } else { $serverout .= "<div class='alert alert-danger' role='alert'>Server does not exist and could not be deleted.</div>"; } $serverout .= $serverForm->render(); } When $serverpage->delete() is executed, $serverad->delete() has no effect. When I comment out $serverpage->delete(), $serverad->delete() is working. I don't get any errors and I already checked that $serverad is a valid page object in all cases. Now I'm clueless of what the problem might be.
  8. Thanks for that link kongondo. It really helped. When I do print_r($GLOBALS), I get: [_POST] => Array ( [name] => Test [uname] => test1 [regemail] => my@email.net [pass] => [_pass] => [sort_repeater1708] => 0 [publish_repeater1708] => 0 [_disable_repeater1708] => 1708 [servername_repeater1708] => [sort_repeater1709] => 1 [publish_repeater1709] => 0 [_disable_repeater1709] => 1709 [servername_repeater1709] => [sort_repeater1710] => 2 [publish_repeater1710] => 0 [_disable_repeater1710] => 1710 [servername_repeater1710] => [sort_repeater1711] => 3 [publish_repeater1711] => 0 [_disable_repeater1711] => 1711 [servername_repeater1711] => [sort_repeater1712] => 4 [publish_repeater1712] => 0 [_disable_repeater1712] => 1712 [servername_repeater1712] => [_reg_servers_add_items] => 0 [timezone] => Europe/Berlin [submitregistration] => Register Account [TOKEN609710988X1412858909] => VehDxck9zIEvN191SQ5G.1HKmG0EeQG41 ) Now I process $_POST with the function from the linked post. $servers = getMultiDimensional($_POST, "servername_repeater"); And get back my array Array ( [1798] => A Server [1799] => Another Server [1800] => And one more Server [1801] => [1802] => ) Now I can go on from there and process my values.
  9. Hello, I'm building a form through the API. In that form I am using a repeater field that is setup with 5 Ready-To-Edit New Repeater items. In the repeater is only one text input field named "servername". Now I'm having trouble accessing the repeater field values when I process the form. I read through the docs at https://processwire.com/api/fieldtypes/repeaters/. But when processing form input post values things seem to be different. I add the field to the form with: $registrationField = $fields->get("reg_servers")->getInputfield($pages->get("/registration")); $registrationField->attr("class","form-control"); $registrationForm->append($registrationField); The field is there in the form and working fine. Now when processing the form, I need to access the values of my repeater. Here's the relevant code: if($input->post->submitregistration) { $registrationForm->processInput($input->post); $servers = $registrationForm->get("reg_servers")->value; var_dump(count($servers)); // this gives int 5, which is fine foreach ($servers as $server) { echo "<pre>"; print_r($server->fields->servername); //servername is my text input field in the repeater echo "</pre>"; } exit(); } In the print_r output I can't find the value of my fields. I also tried var_dump($server->servername) and var_dump($server->servername->value) inside the foreach which gives an empty string. var_dump($server->fields->servername->value) gives null. How can I access my field values?
  10. GOT IT: After moving the $jsConfig script part to the head of my _main.php template file, I don't get the console errors anymore and I have a shiny CKEditor interface attached to my textarea
  11. I followed this thread carefully but still cant get CKEditor to work on the frontend. I'm building my form through the API. My setup: <script> <?php $jsConfig = $config->js(); $jsConfig['urls'] = array( 'root' => $config->urls->root, 'admin' => $config->urls->admin, 'modules' => $config->urls->modules, 'core' => $config->urls->core, 'files' => $config->urls->files, 'templates' => $config->urls->templates, 'adminTemplates' => $config->urls->adminTemplates, 'adminTemplates' => $config->urls->adminTemplates, ); ?> var config = <?php echo json_encode($jsConfig); ?>; </script> <?php $modules->get('JqueryCore'); $modules->get('CKEditor'); //$modules->get('InputfieldCKEditor'); //$config->styles->prepend($config->urls->adminTemplates . "styles/main.css?v=2"); $config->styles->append($config->urls->adminTemplates . "styles/inputfields.css"); $config->styles->append($config->urls->adminTemplates . "styles/ui.css?v=2"); $config->scripts->append($config->urls->JqueryUI . "JqueryUI.js"); $config->scripts->prepend($config->urls->JqueryCore . "JqueryCore.js"); $config->scripts->append($config->urls->adminTemplates . "scripts/inputfields.js"); So I think I'm loading everything necessary and in the correct order. Even when I switch $modules->get('InputfieldCKEditor'); for $modules->get('CKEditor');, the editor doesn't show. I get console errors: Uncaught TypeError: Cannot read property 'editors' of undefined (index):111 Uncaught TypeError: Cannot read property 'plugins' of undefined InputfieldCKEditor.js?v=128:16 line 111 is <textarea id="Inputfield_ad_content" class="FieldtypeTextarea InputfieldMaxWidth" name="ad_content" rows="5"></textarea> All scripts are loaded and visible in the resources tab of chrome debug console. Now I'm lost and any pointers to a solution would be great.
  12. I don't know about bumping the limit further up. But when setting up file downloads, there are some useful functions in the API that you could use. E.g. if you want to allow downloads only for certain users. Here's a post that helped.me.out: https://processwire.com/talk/topic/3634-down-uploads-on-a-per-user-policy/
  13. Thanks again. That helped. I'm using the API to build my forms. They have different names and ids already. When I create the submit button like // submit button! $submit = $modules->get("InputfieldSubmit"); $submit->label = " "; $submit->attr("value","Save Changes"); $submit->attr("id+name","submitprofile"); //Notice submitprofile here - that did the trick $submit->attr("class","btn btn-success"); $profileForm->append($submit); and check if data should be processed with if ($input->post->submitprofile) { //do processing here } It is working and other form submissions do not interfere anymore
  14. Each form has its own. I meanwhile checked that post data is only available for the form that was submitted. So the problem seems to be in my form processing logic somewhere. I will first try myself and find that problem and then report back here. Thank you so far kongondo.
  15. I tried that, too. For example I have email fields in 2 forms. Before they both had name "email". After renaming one of them to "profilemail", I still get unwanted effects on the email field and vice versa.
  16. Hi, I process 3 different forms with 3 different ids/names in the same template. Now my post values seem to get mixed up between the forms. What I tried is $profileForm->processInput($input->post); if ($profileForm->id == "profile-form") { //do something } Analogue with the other 2 forms. But that didn't help. In pure PHP I would use $_POST['profile-form']. But I want to stick wit the PW API. There I found $input->post["name"]. var_dump($input->post["profile-form"]) is null. How can I access and process only the data from my profile-form form using the API? EDIT: Also var_dump($input->post) does not reveal anything about the form id
  17. Thanks! I did try to edit the first post, but not in full editor mode. Now I know
  18. Maybe you can add SOLVED to the thread headline. Thanks.
  19. I can't mark the topic as solved. Maybe because it has been moved?
  20. @kongondo Thanks for moving it. Unfortunately I was just about to post at the same time and things got messed up so I'm overwriting this post. Finally my hook module is working. Big thanks to Soma again! Here's the final code: <?php class CleanupUserPages extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Cleanup User Data', 'version' => 0.1, 'summary' => 'Trashes all pages that where created by a user after user has been deleted', 'singular' => true, 'permanent' => false, 'permission' => 'user-admin', 'autoload' => true, ); } public function init() { $this->pages->addHookBefore("delete", $this, "hookDeleteUsers"); } public function hookDeleteUsers($event){ $page = $event->arguments("page"); if ($page->id && $page->template->name === "user") { $userPages = wire("pages")->find("created_users_id={$page->id}"); foreach ($userPages as $userPage) { wire("pages")->trash($userPage); } $this->message("All pages of user {$page->name} deleted"); } } } ?> I first had problems accessing the page template. The $page object returned by $event->arguments("page") works different from the standard $page object in templates. It took me a while to find that I have to use $page->template->name === "user". exit(var_dump($page)) was helpful.
  21. For your password change functionality you could use something like this <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'password-form'); // create password inputs from the built in PW password field $field = $modules->get("InputfieldPassword"); $field->label = "My new Password"; $field->attr("id+name","pass"); $form->append($field); // submit button! $submit = $modules->get("InputfieldSubmit"); $submit->label = " "; $submit->attr("value","Save Changes"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); if ($form->id == "password-form") { //only process input from password form in case you have more forms in your dashboard //here you could do some validation logic but I don't think it is necessary if you only have password fields //to do validation and print out errors for the password field you would do something like $pass = $form->get("pass"); $_pass = $form->get("_pass"); if ($pass != $_pass) { $pass->error("passwords do not match"); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { //save new password $pass = $form->get("pass")->value; if ($pass != '') { $user->of(false); $user->pass = $pass; $user->save(); $user->of(true); } $out .= "Your changes have been saved."; $out .= $form->render(); } } } else { // render out form without processing $out .= $form->render(); } echo $out; ?> Note: don't sanitize passwords as that might change them and then user can't login.
  22. OK, my hookDeleteUsers function now reads public function hookDeleteUsers($event){ exit("hallo"); $userpage = $event->arguments("page"); if($userpage->id){ $userPages = wire("pages")->find("created_users_id={$userpage->id}"); foreach ($userPages as $userPage) { wire("pages")->trash($userPage); } $this->message("All pages of user {$userpage->name} deleted"); } } But I don't get a "hallo" on delete and all user's pages are still there. So I guess the hook doesn't get called.
  23. Based on Somas input, my CleanupUserPages.module now contains: <?php class CleanupUserPages extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Cleanup User Data', 'version' => 0.1, 'summary' => 'Trashes all pages that where created by a user after user has been deleted', 'singular' => true, 'permanent' => false, 'permission' => 'user-admin', 'autoload' => true, ); } public function init() { $this->users->addHookBefore("delete", $this, "hookDeleteUsers"); } public function hookDeleteUsers($event){ $userpage = $event->arguments("page"); if($userpage->id){ $userPages = $pages->get("created_users_id={$userpage->id}"); $this->pages->trash($userPages); $this->message("pages deleted"); } } } ?> I have installed the module. But when I delete a user, nothing happens. To test if the module gets called, I added var_dump($userpages); return; right after $userpage = $event->arguments("page"); But still nothing happens. It seems like the module code is not being executed at all. Does $this->users->addHookBefore make sense or do I need to define the hook in some other way?
  24. Thank you kongondo, this is working great!
×
×
  • Create New...