symfony1 - symfony 1.1 sfNumberValidator plugin code in php -
i have validation check in validate/confirm.yml on field postalcode as:
postalcode: required: yes required_msg: enter_valid_postalcode validators: numbervalidator numbervalidator: class: sfnumbervalidator nan_error: not_a_number_error
for reason want move logic or same functionality of class sfnumbervalidator in action file.
like
class registeractions extends sfactions { public function validateconfirm() { .... ... $postalcode = $this - > getrequestparameter('postalcode'); if (postalcode != '') { //do same kind of validation sfnumbervalidator } } .... }
you have create sfnumbervalidator
instance , call execute
method.
something this:
if ($postalcode != '') { $validator = new sfnumbervalidator($this->getcontext(), array( 'nan_error' => 'not number', 'min' => 10000, 'max' => 99999 )); $error = null; if(!$validator->execute($potalcode, $error)){ //here $error has message want show user } }
ps: min , max suggestion should maybe use more explicit postal code case
Comments
Post a Comment