views:

47

answers:

1

I am working with a series of forms that have subforms embedded into them and I am trying to work out if I can make getValues return the values without the array notation on the subform.

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());

Gives me the output:

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

But I would actually like the output to be:

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

Any easy way of doing this without overriding Zend_Form functions?

+1  A: 

Something like this may be a start:

$data = array();
foreach ($form->getSubForms() as $subform) {
     $data += $subform->getValues();
}
Benjamin Cremer