Cphalcon: Validators still run, even if there is no PresenceOf

Created on 25 Mar 2016  路  8Comments  路  Source: phalcon/cphalcon

I noticed that when I don't add PresenceOf validator to the element, during validation the form - validators will still run for this item.

$element = new Text('test');
$element->setFilters(array('striptags', 'int'));
$element->addValidators(array(
    /* new PresenceOf(array(
        'message' => 'please fill in'
    )), */
    new Between(array(
        'minimum' => 0,
        'maximum' => 100,
        'message' => 'The value must be between 0 and 100'
    )),
));
$this->add($element);

Show error "The value must be between 0 and 100"

not a bug

All 8 comments

I guess it's a bug beacause this validator should run only if it's not empty.

I guess also
@Jurigag can you look? https://github.com/phalcon/cphalcon/issues/11584

@sergeyklay can you look? I guess it's a bug

Which version of Phalcon did you use

I use Phalcon 2.1.0.RC1

You could add ''allowEmpty' => true' to the validator, allowing empty submition.

$element = new Text('test');
$element->setFilters(array('striptags', 'int'));
$element->addValidators(array(
    new Between(array(  
        'minimum' => 0,
        'maximum' => 100,
        'message' => 'The value must be between 0 and 100',
        'allowEmpty' => true
    )),
));
$this->add($element)

https://docs.phalconphp.com/en/latest/reference/validation.html#avoid-validate-empty-values

Thanks to everybody

Was this page helpful?
0 / 5 - 0 ratings