コード例 #1
0
 public function __construct()
 {
     parent::__construct('address');
     $this->setHydrator(new ClassMethodsHydrator(false))->setObject(new Entity\Address());
     $street = new \Zend\Form\Element('street', array('label' => 'Street'));
     $street->setAttribute('type', 'text');
     $city = new CityFieldset();
     $city->setLabel('City');
     $this->add($street);
     $this->add($city);
 }
コード例 #2
0
 public function __construct()
 {
     parent::__construct('country');
     $this->setHydrator(new ClassMethodsHydrator())->setObject(new Entity\Country());
     $name = new \Zend\Form\Element('name', array('label' => 'Name of the country'));
     $name->setAttribute('type', 'text');
     $continent = new \Zend\Form\Element('continent', array('label' => 'Continent of the city'));
     $continent->setAttribute('type', 'text');
     $this->add($name);
     $this->add($continent);
 }
コード例 #3
0
ファイル: CityFieldset.php プロジェクト: haoyanfei/zf2
 public function __construct()
 {
     parent::__construct('city');
     $this->setHydrator(new ClassMethodsHydrator(false))->setObject(new Entity\City());
     $name = new \Zend\Form\Element('name', array('label' => 'Name of the city'));
     $name->setAttribute('type', 'text');
     $zipCode = new \Zend\Form\Element('zipCode', array('label' => 'ZipCode of the city'));
     $zipCode->setAttribute('type', 'text');
     $country = new CountryFieldset();
     $country->setLabel('Country');
     $this->add($name);
     $this->add($zipCode);
     $this->add($country);
 }
コード例 #4
0
ファイル: AddressFieldset.php プロジェクト: pnaq57/zf2demo
 public function __construct()
 {
     parent::__construct('address');
     $this->setHydrator(new ClassMethodsHydrator(false))->setObject(new Entity\Address());
     $street = new \Zend\Form\Element('street', array('label' => 'Street'));
     $street->setAttribute('type', 'text');
     $city = new CityFieldset();
     $city->setLabel('City');
     $this->add($street);
     $this->add($city);
     $phones = new \Zend\Form\Element\Collection('phones');
     $phones->setLabel('Phone numbers')->setOptions(array('count' => 2, 'allow_add' => true, 'allow_remove' => true, 'target_element' => new PhoneFieldset()));
     $this->add($phones);
 }
コード例 #5
0
ファイル: FormTest.php プロジェクト: rafalwrzeszcz/zf2
 /**
  * @group ZF-8494
  */
 public function testGetValidSubFormValues()
 {
     $data = array('sub' => array('valid' => 1234, 'invalid' => 'invalid', 'noElement' => 'noElement'));
     $subForm = new \Zend\Form\SubForm();
     $validElement = new \Zend\Form\Element("valid");
     $validElement->addValidator(new \Zend\Validator\Int());
     $subForm->addElement($validElement);
     $invalidElement = new \Zend\Form\Element('invalid');
     $invalidElement->addValidator(new \Zend\Validator\Int());
     $subForm->addElement($invalidElement);
     $this->form->addSubForm($subForm, 'sub');
     $this->assertEquals(array('sub' => array('valid' => 1234)), $this->form->getValidValues($data));
 }
コード例 #6
0
 /**
  * Render single element
  * 
  * @access public
  * @param FormInterface $form
  * @param Zend\Form\Element $element
  * @return string element HTML content
  */
 public function renderElement($form, $element)
 {
     $inlineForm = false;
     if (strpos($form->getAttribute('class'), "form-horizontal") === false) {
         $inlineForm = true;
     }
     $elementContent = '';
     // add required class to all required elements
     if (!empty($element->getAttribute('required')) && !$element->getLabelOption("disable_html_escape")) {
         $labelAttributes = $element->getLabelAttributes();
         $labelClass = isset($labelAttributes["class"]) ? $labelAttributes["class"] : "";
         $labelAttributes["class"] = $labelClass . " required";
         $element->setLabelAttributes($labelAttributes);
     }
     // Add Id to all form elements
     // When element has an Id, Label tag won't enclose form element
     if (empty($element->getAttribute('id'))) {
         $element->setAttribute('id', $form->getAttribute('name') . "_" . $element->getAttribute('name'));
     }
     $labelAbsent = false;
     $formElementAppendString = '';
     if (empty($element->getLabel()) && $element->getAttribute('type') !== "hidden") {
         $labelAbsent = true;
     }
     if ($labelAbsent === true && (strpos($element->getAttribute('class'), "btn") === false || strpos($element->getAttribute('class'), "btn") !== false && strpos($element->getAttribute('class'), "pull") === false) && $inlineForm === false) {
         $elementContent .= "<dt>&nbsp;</dt>";
     } else {
         $divAttributes = "";
         if ($inlineForm === true) {
             $divAttributes = "class='form-group'";
         }
         $elementContent .= "<div {$divAttributes} >";
         $formElementAppendString = '</div>';
     }
     // Change submit button text to edit if form is an edit form
     if ($element instanceof Submit && $form->isEditForm === true) {
         if (property_exists($form, "isAdminUser") && $form->isAdminUser === false && $form->needAdminApproval === true) {
             $element->setValue(FormButtons::SUBMIT_FOR_ADMIN_APPROVAL_BUTTON_TEXT);
         } elseif ($element->getValue() == FormButtons::CREATE_BUTTON_TEXT) {
             $element->setValue(FormButtons::EDIT_BUTTON_TEXT);
         }
     }
     $elementContent .= $this->getView()->formRow($element);
     $elementContent .= $formElementAppendString;
     return $elementContent;
 }