On this page
Caution
The documentation you are viewing is for an older version of this component.
Switch to the latest (v3) version.
View Helpers
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 Laminas\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 Laminas\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">