assigning values to elements in nested zend sub forms
I have a 3 tier form structure.
There's a main form, frmMain (which acts more like a container form) which has subforms e.g frmSubFacts. And these sub forms such as frmSubFacts have subforms; for example: frmTabSubCountry. The innermost subform contains the form elements such as text fields. These are grouped using the setBelongsTo method at the form level.
The code uses ZendX_JQuery to render these forms across 2 tab lines such that frmSubFacts and other outer sub forms are within the top tabs, and based on user selection, the sub-subforms (such as frmTabSubCountry) are displayed along a second inner tab line.
The form renders well. The only problem is programmatically setting values to the fields/elements within the innermost sub forms.
The element fields names are rendered based on their hierarchy and relationship such that a text box name could be: Facts[Country][county_name].
However, how do I get to assign a value to this field? I have tried the following options:
$arrFormData['Facts[Country][county_name]'] = 'Singapore';
$Form->populate(array('Facts'=>
array('Country'=> array('country_name'=> 'Singapore'))));
$form->Facts->Country->country_name->setValue('Singapore');
$form->getSubFo开发者_如何学Gorm('Facts')
->getSubForm('Country')
->getElement('country_name')->setValue('Singapore');
Although the application renders well and POST actions are as expected, the last line to get Subforms fails after getting the 'Facts' subform. Thanks for helping
Check if this helps:
$this->element->Facts->Country->country_name->setValue('Singapore');
精彩评论