Laminas\Form\Element\Range is meant to be paired with the FormRange helper for HTML5 inputs with type "range". This element adds filters and validators to its input filter specification in order to validate HTML5 range values on the server.

Basic Usage

This element automatically adds a type attribute of value range.

use Laminas\Form\Element;
use Laminas\Form\Form;

$range = new Element\Range('range');
$range->setLabel('Minimum and Maximum Amount');
    'min'  => '0',   // default minimum is 0
    'max'  => '100', // default maximum is 100
    'step' => '1',   // default interval is 1

$form = new Form('my-form');

Using array notation:

use Laminas\Form\Element;
use Laminas\Form\Form;

$form = new Form('my-form');
    'type' => Element\Range::class,
    'name' => 'range',
    'options' => [
        'label' => 'Minimum and Maximum Amount',
    'attributes' => [
        'min' => 0, // default minimum is 0
        'max' => 100, // default maximum is 100
        'step' => 1, // default interval is 1

Set all attributes before calling prepare

The min, max, and step attributes should be set prior to calling Laminas\Form::prepare(). Otherwise, the default input specification for the element may not contain the correct validation rules.

Public Methods

The Range element extends the Number element, and inherits its methods, with the following changes:

Method signature Description
getInputSpecification() : array Returns a input filter specification, which includes Laminas\Filter\StringTrim and will add the appropriate validators based on the values from the min, max, and step attributes. See the Number element for more information. The Range element differs from Laminas\Form\Element\Number in that the Laminas\Validator\GreaterThan and Laminas\Validator\LessThan validators will always be present. The default minimum is 1, and the default maximum is 100.