本文整理汇总了PHP中Zend_Form_SubForm::setElementsBelongTo方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_SubForm::setElementsBelongTo方法的具体用法?PHP Zend_Form_SubForm::setElementsBelongTo怎么用?PHP Zend_Form_SubForm::setElementsBelongTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_SubForm
的用法示例。
在下文中一共展示了Zend_Form_SubForm::setElementsBelongTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
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'));
}
示例2: init
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,
// ));
}
示例3: testCanValidatePartialNestedFormsWithElementsBelongingToArrays
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']));
}
示例4: testElementsRenderAsMembersOfSubFormsWithElementsBelongTo
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);
}