Source of file FormCheckbox.php
Size: 2,463 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Form/View/Helper/FormCheckbox.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Form\View\Helper; use Zend\Form\ElementInterface; use Zend\Form\Element\Checkbox as CheckboxElement; use Zend\Form\Exception; class FormCheckbox extends FormInput { /** * Render a form <input> element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof CheckboxElement) { throw new Exception\InvalidArgumentException(sprintf( '%s requires that the element is of type Zend\Form\Element\Checkbox', __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__ )); } $attributes = $element->getAttributes(); $attributes['name'] = $name; $attributes['type'] = $this->getInputType(); $attributes['value'] = $element->getCheckedValue(); $closingBracket = $this->getInlineClosingBracket(); if ($element->isChecked()) { $attributes['checked'] = 'checked'; } $rendered = sprintf( '<input %s%s', $this->createAttributesString($attributes), $closingBracket ); if ($element->useHiddenElement()) { $hiddenAttributes = array( 'name' => $attributes['name'], 'value' => $element->getUncheckedValue(), ); $rendered = sprintf( '<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket ) . $rendered; } return $rendered; } /** * Return input type * * @return string */ protected function getInputType() { return 'checkbox'; } } |