View Helpers
In This Article
FormNumber
The FormNumber
view helper can be used to render an <input type="number">
HTML form input. It is meant to work with the Number element,
which provides a default input specification for validating numerical values.
Basic usage
use Zend\Form\Element;
$element = new Element\Number('my-number');
// Within your view...
echo $this->formNumber($element);
Output:
<input type="number" name="my-number" value="">
Usage of min
, max
and step
attributes:
use Zend\Form\Element;
$element = new Element\Number('my-number');
$element->setAttributes([
'min' => 5,
'max' => 20,
'step' => 0.5,
]);
$element->setValue(12);
// Within your view...
echo $this->formNumber($element);
Output:
<input type="number" name="my-number" min="5" max="20" step="0.5" value="12">
Found a mistake or want to contribute to the documentation? Edit this page on GitHub!