Jump to content

gebeer

Members
  • Posts

    1,554
  • Joined

  • Last visited

  • Days Won

    48

Everything posted by gebeer

  1. 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.
  2. 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.
  3. 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.
  4. 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?
  5. 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
  6. 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.
  7. 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/
  8. 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
  9. 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.
  10. 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.
  11. 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
  12. Thanks! I did try to edit the first post, but not in full editor mode. Now I know
  13. Maybe you can add SOLVED to the thread headline. Thanks.
  14. I can't mark the topic as solved. Maybe because it has been moved?
  15. @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.
  16. 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.
  17. 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.
  18. 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?
  19. Thank you kongondo, this is working great!
  20. Hi, I'm trying to setup a page field with a custom selector. Intention is to show only pages of the currently logged in user in the select drop down. Here's what I tried in the field setup: I also tried But I guess this doesn't make a lot of sense because when the page is created and has not been saved yet, the $page->createdUser isn't there yet. I always get an empty select It seems like the page field is not aware of the $user object. Is there any way how I could filter the pages by created_users_id, maybe through a hook on that field?
  21. Thanks again Soma, for your help. Your explanations again are really clear to understand. Based on what I know now, I will try and put the module together. @admins: I should have posted this in the modules forum. You're welcome to move it over there.
  22. Thanks Martijn. I just followed a link to Captain Hook on https://processwire.com/api/hooks/. When I browse http://processwire.com/api/hooks/captain-hook/ the site is working. Whom can I notify and inform about this issue? Github issues?
  23. Hello, I'm trying to learn more about hooks and visited Captain Hook. That page is currently not loading any styles and scripts. My console says: Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/css/anchor.css" Loading mixed (insecure) display content on a secure page "http://somatonic.github.com/Captain-Hook/hook.png" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/jquery.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/quicksilver.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/main.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/jquery.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/quicksilver.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/main.js"
  24. Now I'm aware of lightning.pw, too. Awesome!
×
×
  • Create New...