Search code examples
phpphpactiverecord

PHPActiveRecord allow_blank, allow_null not working on validations


I have the following validator function.

static $validates_size_of = array(
        array('contactfirstname'    , 'within' => array(1,50),  'allow_null' => true),
        array('contactlastname'     , 'within' => array(1,50),  'allow_null' => true),
        array('contactemail'        , 'within' => array(5,255), 'allow_null' => true), //A@A.A ~ smallest possible email is 5 characters.
        array('companyemail'        , 'within' => array(5,255), 'allow_null' => true, 'allow_blank' => true), //A@A.A ~ smallest possible email is 5 characters.
        array('companyname'         , 'within' => array(1,75),  'allow_null' => true),
        array('contactphonenumber'  , 'within' => array(10,20), 'allow_null' => true),
        array('companyphonenumber'  , 'allow_null' => true, 'allow_blank' => true, 'within' => array(10,20)),
        array('address'             , 'within' => array(1,120))
    );

For companyphonenumber, I want to restrict the characters to within 10 to 20 but I also want to allow there to be a blank string or null if nothing was entered. If something was entered however, then it should do the 10 to 20 characters long validation check.

This does not work however. Instead the within validation seems to still trigger when the item is blank or null. Am I doing something wrong, or does PHPActiveRecord have a bug here?


Solution

  • It turns it this actually DOES work correctly, I just made a stupid error. My apologies. Ignore this question.