$mainForm = new Zend_Form(); $subForm = new Zend_Form_SubForm(); $subForm->addElement('text', 'firstName', array( 'label' => 'First Name:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('Alpha') )); $subForm->addElement('text', 'lastName', array( 'label' => 'Last Name:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('Alpha') )); $mainForm->addSubForm($subForm, 'person');
$mainForm = new Zend_Form(); $mainForm->addElement('text', 'firstName', array( 'label' => 'First Name:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('Alpha') )); $mainForm->addElement('text', 'lastName', array( 'label' => 'Last Name:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('Alpha') )); $contactForm = new Zend_Form_SubForm(); $contactForm->addElement('text', 'email', array( 'label' => 'Email:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('EmailAddress') )); $mainForm->addSubForm($contactForm, 'contact[email]');In this example, we again create a mainForm with two text elements for first name and last name. We also create a subForm called contactForm with a text element for email. Instead of specifying a name for the subForm, we use array notation to nest it under the mainForm's 'contact' element, which has a 'email' subkey. Package library: Zend Framework.