array
'subQuantity' =>
array
'quantity_6' => string '23' (length=2)
'quantity_16' => string '23' (length=2)
'quantity_18' => string '23' (length=2)
'update' => string 'Update' (length=6)
美好的一天!我刚从我现有的zend表单创建了一个子表单,并在表单提交时获取这些数据。根据发布的数据(quantity_ elements),我想将值设置为子表单元素。可能吗?提前致谢。 欢呼和快乐的编码!
答案 0 :(得分:8)
不确定是要一次设置单个子表单元素的值还是所有子表单元素的值。不过你可以使用populate方法。例如:
$yourForm->populate(array(
'subQuantity' => array(
'quantity_6' => 'some value 1',
'quantity_16' => 'some value 2',
'quantity_18' => 'some value 3',
)
));
编辑:
以下是设置单个字段的几种方法:
$yourForm->populate(array(
'subQuantity' => array(
'quantity_16' => 'some value',
)
));
// OR
$yourForm->getSubForm('subQuantity')->getElement('quantity_16')->setValue('some value');
// this also should work (not sure if it works with underscore in 'quantity_16' though)
$yourForm->subQuantity->quantity_16->setValue('some value');
答案 1 :(得分:0)
$formSuper = new ContractLink_Form_ContractAllotmentSuper();
foreach($allotments as $key => $allotment)
{
$form = new ContractLink_Form_ContractAllotment();
$form->populate($allotment);
$formSuper->addSubForm($form, 'contractAllotmentForm' . $key);
}