Jump to content

kongondo

PW-Moderators
  • Posts

    7,479
  • Joined

  • Last visited

  • Days Won

    146

Everything posted by kongondo

  1. Works fine for me in an auto-load module in ProcessWire 3.0.42 using the code below. All fields are saved correctly, both page and non-page fields. public function init() { $this->pages->addHookBefore("FieldtypeMulti::savePageField", $this, "hookBefore"); } public function hookBefore(HookEvent $event) { $page = $event->arguments[0]; $this->newPage($page);// calls method to create new page $this->message("we hooked into page with id: {$page->id}"); } public function newPage($parent) { $p = new Page(); $p->template = 'basic-page'; $p->parent = $parent; $p->title = 'Test Child Page'; $p->save(); }
  2. Welcome to PW and the forums @webhoes, I didn't go through your whole code but noticed this: if (waves = 0)//....... That's not a comparison but an assignment. Should be if (waves == 0)//.... // or....depending on your needs if (waves === 0) //... Other than that, you might want to separate the PHP from JavaScript. E.g. for the checked input..., in a foreach loop, assign a CSS class, e.g. 'checked-input' and use that to find elements that are checked.
  3. Unless you are in a PHP Class, you should not be using $this at all, as pointed out earlier. You don't need this line at all: //$wire = $this->wire();// this is not needed in your context It is a good idea, to get a few basic PHP tutorials under your belt before starting to use ProcessWire . Given that you are setting up something as important as a user registration feature, I highly recommend you have a look at such tutorials.
  4. Those variables are always available to you. You don't need to do anything special. The one care you should take is not to overwrite them. # outside a function // will echo the integer value of an input called 'id' that was sent via $_GET echo (int) $input->get->id; // will echo the sanitized value of an input 'title' that was sent by $_POST echo $sanitizer->text($input->post->title); If in a function then: # inside a function // will echo the integer value of an input called 'id' that was sent via $_GET echo (int) wire('input')->get->id; // will echo the sanitized value of an input 'title' that was sent by $_POST echo wire('sanitizer')->text((wire('input')->post->title)); Of course, if inside a function or class, and you will be using lot's of wire('input'), then you can assign that to a variable at the start of the function/class method, i.e. $input = $this->wire('input')->post;// #1. if expecting only post variables // or $post = $this->wire('input')->post; $input = $this->wire('input');// if expecting either get or post or cookie // or $input = wire('input');// you get the idea // then, in relation to #1 above, you can do $id = (int) $post->id; If you have a specific issue, please address it. What is working? What is not? etc... http://processwire.com/api/variables/
  5. ProcessWire's WireMail base class https://processwire.com/api/ref/mail/ https://processwire.com/api/ref/wire-mail/ Example third-party module implementations http://modules.processwire.com/modules/wire-mail-swift-mailer/
  6. A couple of examples Outside function and class $page; $pages; $sanitizer; $input; $modules; $templates; $fields; $user; $users; $log; $session; $config; Inside function wire('page'); wire('pages'); wire('sanitizer'); wire('input'); wire('modules'); wire('templates'); wire('fields'); wire('user'); wire('users'); wire('log'); wire('session'); wire('config'); Inside class $this->wire('page');// also $this->page; $this->wire('pages');// -ditto- $this->wire('sanitizer');// -ditto- $this->wire('input');// -ditto- $this->wire('modules');// -ditto- $this->wire('templates');// -ditto- $this->wire('fields');// -ditto- $this->wire('user');// -ditto- $this->wire('users');// -ditto- $this->wire('log');// -ditto- $this->wire('session');// -ditto- $this->wire('config');// -ditto- Welcome to PW and the forums You may also want to use PW core email class + read up on the recent vulnerability regarding PHPMailer Class (if you haven't already)
  7. Brilliant! Your code could be optimised further like so: $childrenIDs = implode('|', $oldchildrenids); foreach ($pages->find("id=$childrenIDs") as $child) { $child->delete(); $this->message("{$child->id} wurde gefunden und gelöscht"); $childRepeaterPage = $repeaterPage->child("name=for-page-{$child->id}"); // will also delete the repeat item pages, e.g. the '1234567890' if ($childRepeaterPage->id) $pages->delete($childRepeaterPage, true); } In the find, we only fetch the children whose IDs we saved earlier, rather than all children first, then checking their IDs.
  8. // Array of template IDs that are allowed for children. Blank array indicates "any" $page->parent->template->childTemplates // Array of template IDs that are allowed for parents. Blank array indicates "any" $page->template->parentTemplates ...as per notes in core files...
  9. No...the older children. You will need to grab the first, e.g. into a variable, or their IDs then delete them.
  10. The duplicate entry went away for me only if I created the new children first, then deleted the older children. Repeater items would be copied over fine to the new child pages. The only issue then was that for some reason, I couldn't delete their leftover repeater pages...
  11. Excellent! Glad it worked and thanks for sharing the final solution. Similar to what Adrian was saying then (basically a new parent). @adrian, thanks for the ideas
  12. That would require a different repeater field for the child pages, no? In addition, from what I can tell, he wants to delete the older children.
  13. Found a working solution. If you move the code to delete the child pages to AFTER creation of the new child pages, it works. You can then delete the older children pages. After that though, I hit another snag. Haven't been able to delete the repeater pages of the older children
  14. Just seeing @adrian answer. That's definitely it. I've run out of time so can't test further. See if Adrian's solution works. If not, hopefully others chime in, meanwhile. Quick btw: In the code where you delete child pages, no need to delete their repeater pages there as well. They will be automatically deleted when you delete the child pages.
  15. Is this getting saved anywhere btw? $page->recurring = 0; Managed to duplicate the error you are getting. Working on it; will get back to you.
  16. Actually, it makes no difference. I have tested in PW 2.7 and 3.0.42, with each having the same title and it still works. Both adding to repeaters and deleting child pages and their respective repeaters work. Could you post your Hook code itself? i.e. how you are hooking.
  17. This is a strange line. $k->title = $page->title; You child pages will all have the same title; and that title is identical to the parent page. The child pages themselves will have different names; ProcessWire will ensure that. However, I don't know if the same applies to the repeater pages. My suspicion is that this is what is causing the 'integrity constraint' error. I haven't tested yet.
  18. Quick BTWs... In a module context, output formatting is always off (i.e. false), so no need to set it yourself. No need to 'get' the same parent over and over in the loop. Do it outside the loop What is $page in your case? What PW version are you working on? The following code works for me as advertised, in ProcessWire 2.7 and 3.0.42. All parent repeater fields contents are copied over to the children repeater fields $children = array('What We Do', 'Our Mission', 'Our History', 'Our Staff'); $parent = $pages->get('/about-us/'); foreach ($children as $title) { $k = new Page(); $k->template = 'basic-page'; $k->parent = $parent; $k->title = $title; $k->repeater_test->import($parent->repeater_test); $k->save(); } The code above results in this tree under Home And this tree under repeaters. The crossed out repeater items are the unpublished 'ready to edit repeater items' As you can see, names only have to be unique under the same parent (not just for repeaters but throughout ProcessWire)
  19. Something funky going on there. I have tested the code and it definitely works. Any errors? Does a visual check reveal anything? e.g. is that child page there? Is the repeater page there? Does it work outside a module context? Do you have Tracy/Debug on? Edit Also...did you take note of my code changes?
  20. My bad...The child page has to be deleted first: $page = $this->wire('pages')->get(1234); $pages = $this->wire('pages'); $repeaterID = $this->wire('fields')->get('eventpricerepeater')->id; // this is the 'repeater_field_name' page $repeaterPage = $pages->get("parent.name=repeaters, name=for-field-$repeaterID"); foreach ($page->children("include=all") as $child) { $id = $child->id; // first delete the child page $child->delete(); // this is the 'name_of_page_with_repeater' $childRepeaterPage = $repeaterPage->child("name=for-page-$id"); // will also delete the repeate item pages, e.g. the '1234567890' if($childRepeaterPage->id) $pages->delete($childRepeaterPage, true); }
  21. Hi @workdreamer. Welcome to ProcessWire and the forums . You are right. Very bad practice to add/remove from the core . To override any core methods you use Hooks (as long as the method you want to override is hookable). There is an example here regarding Templates: And all about Hooks:
  22. I have re-read your post and I see where we went wrong. Each field has only one repeater page. Its child pages are the parents of the repeater items. Using true in the delete deletes the repeater parent page and its children. That's what my code would do. However, you want to delete only the children. So... Repeaters Hierarchy admin Repeaters repeater_field_name name_of_page_with_repeater 1234567890// repeater item #1 on "name_of_page_with_repeater" 1346798941// repeater item #2 You want to delete 'name_of_page_with_repeater' AND NOT the page 'repeater_field_name' The below (untested) should work (@see amended code in post below...$child has to be deleted first) $page = $this->wire('pages')->get(1234); $pages = $this->wire('pages'); $repeaterID = $this->wire('fields')->get('eventpricerepeater')->id; // this is the 'repeater_field_name' page $repeaterPage = $pages->get("parent.name=repeaters, name=for-field-$repeaterID"); foreach ($page->children("include=all") as $child) { // this is the 'name_of_page_with_repeater' $childRepeaterPage = $repeaterPage->child("name=for-page-{$child->id}"); // will also delete the repeate item pages, e.g. the '1234567890' if($childRepeaterPage->id) $pages->delete($childRepeaterPage, true); $child->delete(); }
  23. Repeaters pages need to be deleted a bit differently // delete repeater page: admin/repeaters/for-field-xxx $repeaterID = $fields->get('name_of_repeater_field')->id; // make sure you get the right repeater page $repeaterPage = $pages->get("parent.name=repeaters, name=for-field-$repeaterID"); if($repeaterPage->id) $pages->delete($repeaterPage, true); Regarding the error, not sure why you are getting it, but you can check like this: if($parent && $parent->id) { }
  24. $out = strip_tags($page->body); echo $out; strip_tags is one way to do it. I'm not sure about performance on a large body of text though. Maybe regex would be faster, I don't know
×
×
  • Create New...