|
Size: | 10335 |
Storage flags: | no_autoload,compress/gzip (29%) |
The FormCheckbox view helper can be used to render a <input type="checkbox"> HTML form input. It is meant to work with the Zend\Form\Element\Checkbox element, which provides a default input specification for validating the checkbox values.
FormCheckbox extends from Zend\Form\View\Helper\FormInput.
Basic usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | use Zend\Form\Element;
$element = new Element\Checkbox('my-checkbox');
// Within your view...
/**
* Example #1: Default options
*/
echo $this->formCheckbox($element);
// <input type="hidden" name="my-checkbox" value="0">
// <input type="checkbox" name="my-checkbox" value="1">
/**
* Example #2: Disable hidden element
*/
$element->setUseHiddenElement(false);
echo $this->formCheckbox($element);
// <input type="checkbox" name="my-checkbox" value="1">
/**
* Example #3: Change checked/unchecked values
*/
$element->setUseHiddenElement(true)
->setUncheckedValue('no')
->setCheckedValue('yes');
echo $this->formCheckbox($element);
// <input type="hidden" name="my-checkbox" value="no">
// <input type="checkbox" name="my-checkbox" value="yes">
|
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.