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); }
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); }
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); }
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); }
/** * @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)); }
/** * 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> </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; }