我正在 Zend Framework 1.9 中使用子表单以及在这些表单上启用 Zend_JQuery 构建一个表单。表单本身很好,所有错误检查等都正常工作。但是我遇到的问题是,当我尝试检索控制器中的值时,我只收到最后一个子表单的表单条目,例如
我的主表单类(速度的缩写):
Master_Form extends Zend_Form
{
public function init()
{
ZendX_JQuery::enableForm($this);
$this->setAction('actioninhere')
...
->setAttrib('id', 'mainForm')
$sub_one = new Form_One();
$sub_one->setDecorators(... in here I add the jQuery as per the docs);
$this->addSubForm($sub_one, 'form-one');
$sub_two = new Form_Two();
$sub_two->setDecorators(... in here I add the jQuery as per the docs);
$this->addSubForm($sub_two, 'form-two');
}
}
这样所有的东西都可以在显示中正常工作,并且当我在未填写所需值的情况下提交时,会返回正确的错误。但是,在我的控制器中,我有这个:
class My_Controller extends Zend_Controller_Action
{
public function createAction()
{
$request = $this->getRequest();
$form = new Master_Form();
if ($request->isPost()) {
if ($form->isValid($request->getPost()) {
// This is where I am having the problems
print_r($form->getValues());
}
}
}
}
当我提交它并且它通过 isValid() 时,$form->getValues() 仅返回来自第二个子表单的元素,而不是整个表单。