public function init() { $this->setAttrib('id', 'org-form-app'); // subforms $organization = new Zend_Form_SubForm(); $statement = new Zend_Form_SubForm(); // Set subform where elements belong to avoid name clashing $organization->setElementsBelongTo('organizationForm'); $statement->setElementsBelongTo('statementForm'); // subform section names //$organization->setLegend("ORGANIZATION"); //$statement->setLegend("STATEMENT OF AGREEMENT AND RESPONSIBILITY"); // Set the method for the display form to POST $this->setMethod('post'); // ========================================================== add fields $this->addOrganizationFields($organization); $this->addStatementFields($statement); // ===================================================================== // Add subforms to main form $this->addSubForms(array('organization' => $organization, 'statement' => $statement)); // Add the submit button $this->addElement('submit', 'submit', array('class' => 'btn btn-info pull-right', 'ignore' => true, 'label' => 'Submit Application')); }
public function init() { $this->setAttrib('id', 'radio-form-app'); // subforms $listener = new Zend_Form_SubForm(); $contact = new Zend_Form_SubForm(); $otherInfo = new Zend_Form_SubForm(); $statement = new Zend_Form_SubForm(); // Set subform where elements belong to avoid name clashing $listener->setElementsBelongTo('listenerForm'); $contact->setElementsBelongTo('contactForm'); $otherInfo->setElementsBelongTo('otherInfoForm'); $statement->setElementsBelongTo('statementForm'); //$listener->setElementDecorators(array('ViewHelper', 'Label')); //$statement->setElementDecorators(array('ViewHelper', 'Label')); // subform section names $listener->setLegend("LISTENER"); $contact->setLegend("ALTERNATIVE CONTACT"); $statement->setLegend("STATEMENT OF AGREEMENT AND RESPONSIBILITY"); // Set the method for the display form to POST $this->setMethod('post'); // ========================================================== add fields $this->addListenerFields($listener); $this->addContactFields($contact); $this->addOtherFields($otherInfo); $this->addStatementFields($statement); // ===================================================================== // Add subforms to main form $this->addSubForms(array('listener' => $listener, 'contact' => $contact, 'otherInfo' => $otherInfo, 'statement' => $statement)); // Add the submit button $this->addElement('submit', 'submit', array('id' => 'submit', 'ignore' => true, 'label' => 'Submit Application', 'class' => 'btn btn-info pull-right')); // Add some CSRF protection // $this->addElement('hash', 'csrf', array( // 'ignore' => true, // )); }
public function testCanValidatePartialNestedFormsWithElementsBelongingToArrays() { $form = new Zend_Form(); $form->setElementsBelongTo('foobar'); $form->addElement('text', 'firstName') ->getElement('firstName') ->setRequired(false); $form->addElement('text', 'lastName') ->getElement('lastName') ->setRequired(true); $subForm = new Zend_Form_SubForm(); $subForm->setElementsBelongTo('foobar[baz]'); $subForm->addElement('text', 'email') ->getElement('email') ->setRequired(true) ->addValidator('NotEmpty'); $subSubForm = new Zend_Form_SubForm(); $subSubForm->setElementsBelongTo('foobar[baz][bat]'); $subSubForm->addElement('checkbox', 'home') ->getElement('home') ->setRequired(true) ->addValidator('NotEmpty'); $subForm->addSubForm($subSubForm, 'subSub'); $form->addSubForm($subForm, 'sub') ->addElement('submit', 'save', array('value' => 'submit')); $data = array('foobar' => array( 'lastName' => 'Cow', )); $this->assertTrue($form->isValidPartial($data)); $this->assertEquals('Cow', $form->lastName->getValue()); $firstName = $form->firstName->getValue(); $email = $form->sub->email->getValue(); $home = $form->sub->subSub->home->getValue(); $this->assertTrue(empty($firstName)); $this->assertTrue(empty($email)); $this->assertTrue(empty($home)); $form->sub->subSub->home->addValidator('StringLength', false, array(4, 6)); $data['foobar']['baz'] = array('bat' => array('home' => 'ab')); $this->assertFalse($form->isValidPartial($data), var_export($form->sub->subSub->home, 1)); $this->assertEquals('1', $form->sub->subSub->home->getValue()); $messages = $form->getMessages(); $this->assertFalse(empty($messages)); $this->assertTrue(isset($messages['foobar']['baz']['bat']['home']), var_export($messages, 1)); $this->assertTrue(isset($messages['foobar']['baz']['bat']['home']['stringLengthTooShort'])); }
public function testElementsRenderAsMembersOfSubFormsWithElementsBelongTo() { $this->form->setName('data')->setIsArray(true); $subForm = new Zend_Form_SubForm(); $subForm->setElementsBelongTo('billing[info]'); $subForm->addElement('text', 'name'); $subForm->addElement('text', 'number'); $this->form->addSubForm($subForm, 'sub'); $html = $this->form->render($this->getView()); $this->assertContains('name="data[billing][info][name]', $html); $this->assertContains('name="data[billing][info][number]', $html); $this->assertContains('id="data-billing-info-name"', $html); $this->assertContains('id="data-billing-info-number"', $html); }