Jump to content

Saving form with data from AJAX (outputFormatting terror!)


Recommended Posts

Posted

Hello,

I am trying to build a form which is saved via AJAX, containing text fields, selects and checkboxes. No matter what I do, I can't get rid of the error "Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved."

The problem is mostly with data coming from selects. I compared my Ajax data with the post data from a regular form submit and afaict it matches.

My special case right now is for two selects from inputfieldPage ("year" and "schaltgruppe_kurbel"), each configured to hold only one page. The form sends single values (page ids) and the error is thrown. I tried converting all single values to arrays with one element, but no success. 

This is my script to save the data. It runs in a module:

$prod = $this->pages->get($this->id);

$prod->of(false); # this doesn't really make a difference but it's here.

$form = $this->modules->get('InputfieldForm');

$fields = $prod->getInputfields();

foreach($fields as $f) $form->append($f);

$form->processInput($this->input->post);
      
foreach($form as $f) $prod->set($f->name, $f->value);

$prod->save(); # ERROR

Can anyone help? I'm really stuck here ...

Thanks,

thomas

PS I also tried leaving out the PW admin specific stuff like processInput and set the input data directly, but no change ...

Posted

Try setting output formatting off in the 2nd foreach as well as saving inside this loop:

foreach($form as $f) {
   $prod->of(false);
   $prod->set($f->name, $f->value);
   $prod->save();
}
Posted

Thanks Kongondo,

I put of(false) almost everywhere now and most of it seems to work. I still need to catch a few fieldtypes in order to get the right info out of them but I'm getting there.

Thanks,

thomas

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...