/** * Render a form <select> element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof SelectElement) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $options = $element->getValueOptions(); if (($emptyOption = $element->getEmptyOption()) !== null) { $options = array('' => $emptyOption) + $options; } $attributes = $element->getAttributes(); $value = $this->validateMultiValue($element->getValue(), $attributes); $attributes['name'] = $name; if (array_key_exists('multiple', $attributes) && $attributes['multiple']) { $attributes['name'] .= '[]'; } $this->validTagAttributes = $this->validSelectAttributes; $rendered = sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value)); // Render hidden element $useHiddenElement = method_exists($element, 'useHiddenElement') && method_exists($element, 'getUnselectedValue') && $element->useHiddenElement(); if ($useHiddenElement) { $rendered = $this->renderHiddenElement($element) . $rendered; } return $rendered; }
/** * Render a form checkbox-group element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof MultiCheckboxGroup) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zork\\Form\\Element\\MutiCheckboxGroup', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $options = $element->getValueOptions(); if (empty($options)) { if (($translator = $this->getTranslator()) !== null) { return '<i>' . $translator->translate('default.empty', 'default') . '</i>'; } else { return ''; } } if (($emptyOption = $element->getEmptyOption()) !== null) { $options = array('' => $emptyOption) + $options; } $attributes = $element->getAttributes(); $value = $element->getValue(); $addAttr = array('type' => 'checkbox', 'name' => substr($name, -2) == '[]' ? $name : $name . '[]', 'required' => empty($attributes['required']) ? null : 'required'); $this->validTagAttributes = $this->validCheckboxGroupAttributes; if (null !== $element->getTranslatorTextDomain()) { $this->setTranslatorTextDomain($element->getTranslatorTextDomain()); } if (empty($attributes['class'])) { $attributes['class'] = 'multi_checkbox'; } return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), sprintf('<input type="hidden" name="%s" value="" />' . PHP_EOL, substr($name, -2) == '[]' ? substr($name, 0, -2) : $name) . $this->renderCheckboxes($options, $value, $addAttr)); }
/** * Render a form <select> element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof SelectElement) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $options = $element->getValueOptions(); if (($emptyOption = $element->getEmptyOption()) !== null) { $options = array('' => $emptyOption) + $options; } $attributes = $element->getAttributes(); $value = $this->validateMultiValue($element->getValue(), $attributes); $attributes['name'] = $name; if (array_key_exists('multiple', $attributes) && $attributes['multiple']) { $attributes['name'] .= '[]'; } $this->validTagAttributes = $this->validSelectAttributes; $size = $element->getOption('size'); if (empty($size)) { return sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value)); } return sprintf('<div class="col-lg-%s col-md-%s col-sm-%s col-xs-%s"> <select %s>%s</select> </div>', $size, $size, $size, $size, $this->createAttributesString($attributes), $this->renderOptions($options, $value)); }
/** * Render a form radio-group element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof RadioGroup) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zork\\Form\\Element\\RadioGroup', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $options = $element->getValueOptions(); if (empty($options)) { if (($translator = $this->getTranslator()) !== null) { return '<i>' . $translator->translate('default.empty', 'default') . '</i>'; } else { return ''; } } if (($emptyOption = $element->getEmptyOption()) !== null) { $options = array('' => $emptyOption) + $options; } $attributes = $element->getAttributes(); $value = $element->getValue(); $additionalAttribures = array('type' => 'radio', 'name' => $name, 'required' => empty($attributes['required']) ? null : 'required'); $this->validTagAttributes = $this->validRadioGroupAttributes; return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), $this->renderRadios($options, $value, $additionalAttribures, $element->getOption('option_attribute_filters'))); }