cb2004 Posted April 14, 2016 Share Posted April 14, 2016 I am using hooks to populate some required field values. The populating is done, but I get an error message if it is a required field regardless if it has been populated. Which hook should I use to save the values, then the page displays without an error? Cheers. $pages->addHookAfter("save", function($event) { $page = $event->arguments(0); // apply job title if a quote is selected, apply customer address if customer selected if ($page->template->id == 48) { if ($page->page_quote && empty($page->title)) { $page->setAndSave("title", $page->page_quote->title); } if ($page->page_customer && empty($page->textarea_1)) { $page->setAndSave("textarea_1", $page->page_customer->textarea_1); } } }); Link to comment Share on other sites More sharing options...
bernhard Posted April 14, 2016 Share Posted April 14, 2016 hi cb, i think addhookafter "saveReady" should be fine. and just set the values, the save will take place afterwards: // change this $page->setAndSave("title", $page->page_quote->title); // to that $page->title = $page->page_quote->title; 2 Link to comment Share on other sites More sharing options...
Juergen Posted April 15, 2016 Share Posted April 15, 2016 If it doesnt work you could also try this one (not tested): $pages->addHookBefore('saveReady', function($event) Link to comment Share on other sites More sharing options...
cb2004 Posted May 17, 2016 Author Share Posted May 17, 2016 Ben provided the correct hook here: https://github.com/ryancramerdesign/ProcessWire/issues/1832 So we end up with: $pages->addHookBefore("ProcessPageEdit::processInput", function($event) { $page = $event->object->getPage(); // apply job title if a quote is selected, apply customer address if customer selected if ($page->template->id == 48) { if ($page->page_quote && empty($page->title)) { $page->setAndSave("title", $page->page_quote->title); } if ($page->page_customer && empty($page->textarea_1)) { $page->setAndSave("textarea_1", $page->page_customer->textarea_1); } } }); 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now