Hi all,
I'm trying to build a Zend_Form which is built using quite a few subforms (ZendXjQuery forms). In only one of these subforms I have some elements which I would like to have added to an array, and therefore I am using belongsTo for those elements.
The HTML rendered is perfect for the form and displays exactly I would imagine with my elements being rendered like <input type="text" name="my_array-input_name" id="my_array[input_name]" value="0" />. So far so good.
The problem comes that when I use $form->isValid() in my controller, this seems to have issues with my arrayed elements. All validation messages are perfect, all the other form elements are fine...
BUT, say for instance I had inputted "999" as my value in one of the array fields, when I post the form, if validation is unsuccessful, then although the other elements in my form remember their posted values, the arrayed elements all get set to 0.
If I post the form with no validation problems, and use Zend_Debug::dump($this->_request->getPost()) in my controller, the array looks the way that I would imagine?! So my guess is that isValid() does not like the way I have built the form? And example of a successful posted array is something like:
array(47) {
["submit"] => string(4) "Save"
["request_token"] => string(32) "0b17c812728b415bb51fe1b65f548725"
["first_name"] => string(5) "foo"
["last_name"] => string(5) "bar"
["my_arrayed_element"] => array(10) {
["example_one"] => string(5) "baz"
...
}
This is the array format that I wish to receive the posted variables in, it's just getting it to stop forgetting the arrayed elements when validation is not successful.
### Small update:
I'm not sure if this'll help but I just stuck some code into the isValid() method of Zend/Form/Element.php and the results suggest that there is no value for the elements using belongsTo() (I know this is not the ideal way of testing but it is quick).
echo '<p>NAME: '.$this->getName();
echo '<br />VALUE: '.$value;
echo '<br />BELONGS TO: ' . $this->getBelongsTo();
All normal fields are fine, but the arrayed fields always seem to default to 0 even if I enter a value such as 25:
NAME: baz
VALUE: 0
BELONGS TO: my_arrayed_element