I'm using Zend Framework 1.12, making a page which have multiple forms in it. I use a single master form and subforms in it. Therefore, I have just one Validation code part. These subforms point to different tables in database. Aim is that, if there is a row in database about that form, form should take values from database as default, to give user chance of change that data. And if there is not a row in database, input of this form will be inserted to db. At first, I can take values from db and show them as values of form elements. But when I change it and try to take values with
$form->getValues();
I cannot access the values entered (or edited) in page, I just re-access the values in database which was put in form as default. This form should be able to edit always, and I have multiple forms for different kinds of data, which will do same thing too. What must I be doing wrong ? Any idea?
(addition) here is a summary of the relevant piece of my controller code:
$masterform = new Application_Form_GeneralForm(); // a class which extends Zend_Form
$form1 = new Application_Form_SmallForm(); // a class which extends Zend_Form_Subform
$masterform->addSubform($form1, 'form1');
// so far, for form 1, no problem. My second form will be
// added to the masterform after this first form is submitted,
// which works fine.
$form2 = new Application_Form_AnotherSmallForm(); // a class which extends Zend_Form_Subform
$request = $this->getRequest();
if ($request->isPost()){
if ($generalform->isValid($request->getPost())) {
$form2->loadValues(); // the part that form elements are filled with data
// taken from db, a method defined in `AnotherSmallForm`
// class. Just assigning values to elements with `setValue()`
$form2->saveValues(); // Here is the problem, another method to save the
// current values to db. (defined in form class). I have to do this in this fragment of code, so i don't know to
// use which order ( saveValues() and loadValues() methods' order )`
$masterform->addSubform($form2, 'form2');
}
}
So, 1st step: $form1 is added to $masterform.
2nd step: $masterform submitted (it only includes $form1 now), then $form2 is added to $masterform. before it is added, the values for $form2 is loaded inside form elements.
3rd step: $masterform submitted, (so is $form1 and $form2). If any change of the values in $form2 , they must be updated in db by this submission.
This is goal of this code, which could not be accomplished because of 3rd step.