0
votes

I have this form:

form action="...." method="get"

Zip Code: input type="text" name="location"

I would like to validate that the zip code's length is five and that they are all numbers.

I'm stuck on how/where to do this without creating a doctrine form and running sfValidators through the configure() function.

I found some documentation to do this in 1.2, but it seems that it has been removed in 1.4.

Thanks for any help!

2

2 Answers

1
votes

It's essentially the same as 1.4 as 1.2. You don't need to create an instance of sfDoctrineForm, just sfForm:

class MyForm extends BaseForm
{
  public function configure()
  {
    $this->setWidget('zip_code', new sfWidgetFormInputText(array(), array('size' => 5, 'maxlength' => 5));
    $this->setValidator('zip_code', new sfValidatorInteger(array('min' => 0, 'max' => 99999));
  }
}

You would then bind the form and use sfForm::getValues() to retrieve the bound values.

0
votes

I wouldn't expect a sfValidatorInteger here, so in Germany zip-codes may also start with a 0 (like "08122") - or whatever all over the world :-)

Take a sfValidatorRegex with "[0-9]+" or sth on your needs !