Martijn Geerts Posted January 21, 2015 Share Posted January 21, 2015 Having a problem with errors staying (1 page reload) to long in $session. On the Inputfield I call ->getErrors(true); to clear the errors for the Inputfield. Works Fine ! But the message in session (on top of the admin) stays 1 page save longer. And I don't know how to get rid of it. Initially I though to delete it from $session directly with: $key = $field->getErrorSessionKey(); // gets the session error key from Inputfield $session->remove($key) // No succes :-( Can somebody help me out here ? <?php public function init() { $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'afterPageEditBuildForm'); } public function afterPageEditBuildForm(HookEvent $event) { $form = $event->return; $page = $event->object->getPage(); if (!$page->id) return; // return if wrong template $template = $page->template; if (strpos($template->name, 'element_') !== 0) return; // table field with defaults $rootParent = $page->rootParent; $table = $rootParent->settings; $allowed = array( 'FieldtypePageTitle', 'FieldtypeText', 'FieldtypeURL', ); foreach ($template->fields as $f) { // only allowed fields if (!in_array($f->type, $allowed)) continue; // Inputfield $obj = $form->getChildByName($f->name); if ($obj->value) { $obj->getErrors(true); continue; } // Find row in rootParent with default value $row = $table->get("template={$template->name}, field={$f->name}"); // Skip if no row is found if (!count($row) || !$row) continue; // clear errors & set trackChange $obj->getErrors(true); $obj->error($this->_('Standaard waarde toegevoed, nog niet opgeslagen.')); $obj->resetTrackChanges(); $obj->trackChange('value'); $obj->value = $row->value; } } Link to comment Share on other sites More sharing options...
ESRCH Posted January 21, 2015 Share Posted January 21, 2015 Here's my take on the problem, but I might be in over my head... When looking at the PW source code for ProcessPageEdit.php, the buildForm function seems to be called on line 112, before the processSave function (which calls processInput) is called on line 115. So when hooking after buildForm, the errors have not yet been set by processInput, so you can't purge them with getErrors(true). Setting the hook on the processInput function might do the trick? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 21, 2015 Author Share Posted January 21, 2015 ProcessInput Is the first method that get's called after a post. That method cleans the data from $input->post, the function compares the posted value with the value in DB. When different, change tracking is called to tell PW that the value has been changed and should be saved and make the data available. The errors I talk about are the errors I set manually the the Inputfield object. Link to comment Share on other sites More sharing options...
ESRCH Posted January 21, 2015 Share Posted January 21, 2015 Oh, OK, in over my head then Thanks for the reply anyway! 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 21, 2015 Author Share Posted January 21, 2015 Not only your head, mine to 1 Link to comment Share on other sites More sharing options...
ESRCH Posted January 21, 2015 Share Posted January 21, 2015 Thanks, I feel better now Link to comment Share on other sites More sharing options...
adrian Posted September 24, 2018 Share Posted September 24, 2018 I know this is ancient, but: $session->errors('clear'); 2 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