1

我正在使用一系列嵌入了子表单的表单,我正在尝试确定是否可以让 getValues 返回没有子表单上的数组表示法的值。

IE:

$form = new Zend_Form();
$subForm = new Zend_Form_SubForm();
$form->addSubForm( $subForm, 'contact' );

$form->addElement(new Zend_Form_Element_Text('name'));
$subForm->addElement( new Zend_Form_Element_Text('phone') );

var_dump($form->getValues());

给我输出:

array(2) {
  ["name"]=>
  NULL
  ["contact"]=>
  array(1) {
    ["phone"]=>
    NULL
  }
}

但我实际上希望输出是:

array(2) {
  ["name"]=>
  NULL
  ["phone"]=>
  NULL
}

在不覆盖 Zend_Form 函数的情况下有什么简单的方法吗?

4

2 回答 2

3

你可以很简单地使用:

$subform->setIsArray(false);
于 2011-02-10T16:21:18.570 回答
1

Something like this may be a start:

$data = array();
foreach ($form->getSubForms() as $subform) {
     $data += $subform->getValues();
}
于 2010-08-05T06:57:38.747 回答