Zend Form - 如何在子表单元素上设置值? [英] Zend Form - How to set values on sub form elements?
本文介绍了Zend Form - 如何在子表单元素上设置值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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_ 元素),我想将值设置为子表单元素.是否可以?提前致谢.欢呼和快乐的编码!
Good day! I just created a subform from my existing zend form and procures this data when form submits. Based on posted data (the quantity_ elements), I would like to set the values to subform elements. Is it possible? Thanks in advance. cheers and happy coding!
推荐答案
不确定您是要设置单个子表单元素的值还是一次设置所有子表单元素的值.不过你可以使用 populate 方法.例如:
Not sure whether you want to set values of individual subform elements or all of them at once. Nevertheless you can use populate method. For example:
$yourForm->populate(array(
'subQuantity' => array(
'quantity_6' => 'some value 1',
'quantity_16' => 'some value 2',
'quantity_18' => 'some value 3',
)
));
以下是设置单个字段的几种方法:
Here are few ways of setting individual fields:
$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');
这篇关于Zend Form - 如何在子表单元素上设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文