BFD Calendar Posted October 6, 2016 Share Posted October 6, 2016 I have a form (by Soma) to change information on a page - a tool lendout system, when someone returns a tool I fill in the return date and the page no longer shows in the lendout list. It worked perfect last semester, now out of the blue there's an error: Error: Exception: Can't save page 3435: /en/lendout/1460370298/: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [return_time] (in /home/mekanoinsa/www/wire/core/Pages.php line 1045) #0 [internal function]: Pages->___save(Object(Page), Array) #1 /home/mekanoinsa/www/wire/core/Wire.php(398): call_user_func_array(Array, Array) #2 /home/mekanoinsa/www/wire/core/Wire.php(333): Wire->runHooks('save', Array) #3 /home/mekanoinsa/www/wire/core/Page.php(1482): Wire->__call('save', Array) #4 /home/mekanoinsa/www/wire/core/Page.php(1482): Pages->save(Object(Page), Array) #5 /home/mekanoinsa/www/site/templates/lendout.php(84): Page->save() #6 /home/mekanoinsa/www/wire/core/TemplateFile.php(182): require('/home/mekanoins...') #7 [internal function]: TemplateFile->___render() #8 /home/mekanoinsa/www/wire/core/Wire.php(398): call_user_func_array(Array, Array) #9 /home/mekanoinsa/www/wire/core/Wire.php(333): Wire->runHooks('render', Array) #10 /home/mekanoinsa/www/wire/modules This is the form code: // get a page $editpage = $page; $ignorefields = array("title","student_name","lendout_time","language_published"); $form = $modules->get("InputfieldForm"); $form->method = 'post'; $form->action = './'; // get the collection of inputs that can populate this page's fields $inputfields = $editpage->getInputfields(); // make all the fields required and add them to the form foreach($inputfields as $inputfield) { if(in_array($inputfield->name, $ignorefields)) continue; $form->add($inputfield); } // the inputfields don't already have a submit button, so we'll add one. $submit = $modules->get("InputfieldSubmit"); $submit->name = "submit"; $submit->value = 'Submit'; // add the submit button the the form $form->add($submit); $out = ''; // process the form if($this->input->post->submit) { // now we assume the form has been submitted. // tell the form to process input from the post vars. $form->processInput($this->input->post); // see if any errors occurred if( count( $form->getErrors() )) { // re-render the form, it will include the error messages $out .= $form->render(); } else { // successful form submission, so populate the page with the new values. $editpage->setOutputFormatting(false); foreach($form as $field) { $editpage->set($field->name, $field->value); } // save it $editpage->save(); $out .= "Page saved."; $out .= $form->render(); } } else { $out .= $form->render(); } echo $out; Link to comment Share on other sites More sharing options...
godmok Posted October 9, 2016 Share Posted October 9, 2016 I have a similar problem. In my case I try to change a page and save a value from this page in the user profile. Here my code: $u = $users->get(123456); $u->setOutputFormatting( false ); $u->user_activation = true; /** * get the only invoice and mark it paid * Payment if there is one invoice */ $invoices = $pages->find( "template=invoice, user_select=$u->id" ); $invoice = $invoices->first(); if ( count( $invoices ) === 1 && $invoice->id ) { $invoice->setOutputFormatting( false ); if ( $invoice->payment_rate === (float) $input->get->amt ) { /** * ERROR occurs if reloading the page with changed value (true/false) * set $u->setOutputFormatting( false ) later before the pass */ $invoice->user_activation = true; $invoice->save(); $u->payment_rate = $invoice->payment_rate; } } $pass = activationAndPassCode(); $u->setOutputFormatting( false ); // have to set it again, without it will create an error $u->pass = $pass; $u->save(); My error message was similar but there was: ... modified and saved. [pass] ... The only fix I could made for now is to put $u->setOutputFormatting(false) again before changing the password ($u->pass = $pass), even if was set in first line. Weird behaviour on my side was: after the first time the error was shown it disappeared after the second. It triggered only on the change of $invoice->user_activation = true|false. So if the value changed in $invoice->user_activation it could not run without the error. Maybe it helps to set you to set setOutputFormatting(false) before your change on the field "return_time" as the error hints to it. 1 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