Problem With Validation Rules (Default And Filter Strip Tags)

Hi guys, i’m having a problem with two validation rules (default, value=>null and filter strip_tags), i cannot use the same attribute with this two validation rules. If i set default null and strip tags, the default rule don’t work. Someone have any idea why this happen?


      array('crx_value', 'default', 'value'=>null),

      array('crx_value', 'filter', 'filter'=>'strip_tags'),



Hello KillCloud!

I think you are making some confusion about the ‘default’ and ‘filter’ validators! If you read the

CDefaultValueValidator, you can check that it does not do any validation but only allows to set a default value at the time validation is performed. About the CFilterValidator, you can read that this validator transforms the data being validated based on a filter. So, basically, how this works?

Imagine this example: you have a database table called tbl_user, with the field ‘username’, and you want to ensure that, if the user don’t enter any data into this field, the application saves the default value ‘guest’ or something else, if the user type something, you want to ensure that the data is saved without any HTML or PHP tags, ie if the user enter ‘<p>ohohoh</p>’ the value that going to be save is ‘ohohoh’, otherwise (an empty value) the value that is going to be saved is ‘guest’.




...

array('username', 'default', 'value' => 'guest'),

array('username', 'filter', 'filter' => 'strip_tags'),

...