Symfony World blog is not maintained anymore. Check new sys.exit() programming blog.

admin generator validation - validating integer input

An easy problem solving solution this time... If you want to have an integer validator for an input, the first thing you may think of using is:

$this->validatorSchema ['number'] =
  new sfValidatorInteger(array('required' => false));

and such code may cause you a lot of troubles because of the following error:
"%value%" is not an integer.
which may be frustrating to find the source of the problem. Integer validator handles validation on schema input value, which means, more or less, complex input (associative array). Need to use the sfValidatorSchemaFilter class:

$this->validatorSchema ['number'] =
  new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false)));

And that's it!

No comments:

Post a Comment