1
votes
            $inputFilter->add(array(
            'name' => 'nightCharges',
            'required' => FALSE,
            'filters' => array(
                array('name' => 'Digits'),
            ),
            'validators' => array(
                array(
                    'name' => 'GreaterThan',
                    'options' => array(
                        'min' => 1,
                        'messages' => array(
                            \Zend\Validator\GreaterThan::NOT_GREATER => 'My message',
                        ),
                    ),
                ),
            ),
        ));

Above is my code snippet for validation in this case for 'check box'. If I set 'required' to "true" and submit empty form, it shows me the default 'Value is required and can't be empty' message and if I set 'required' to 'false' it does't show me any error at all. Even if I submit non digit value it doesn't show me actual error message. Where am I making mistake? Actually I was working on 'Please accept the terms & conditions' check box.

1

1 Answers

1
votes

Rather than using the GreaterThan validator, try using Identical to ensure the value can't be anything other than 1.

'validators' => array(
    array(
        'name' => 'Identical',
        'options' => array(
            'token' => '1',
            'messages' => array(
                Identical::NOT_SAME => 'Please accept the terms & conditions.',
            ),
        ),
    ),
),