views:

141

answers:

1

Hi,

I don't want an empty email field in my form to trigger a Doctrine_Validator_Exception. But, since Doctrine_Validator_Email uses "is_null()" to check for empty (non-existing) values (and the POST ['email'] contains an empty string), it does.

Is this correct? Is there a simple way around this?

This also has an impact when trying to set a column as unique (trying to store a second empty string in the column triggers the validator).

What am I missing?

Thanks in advance, Erland Wiencke

(Symfony 1.4.1/Doctrine 1.2)

A: 

There are several ways, not tested, but seem to work alltogether or separately:

1) $this->validatorSchema['email'] = null;

or

2) $this->validatorSchema['email'] = sfValidatorPass();

or

3) $this->validatorSchema->setOption('allow_extra_fields', true);

or

4) Just set required attribute to false:

$this->widgetSchema['email'] = sfWidgetFormInputText(array('required' => false));
Darmen
Thanks, but the sf validators are not the issue. There also appears to be a couple of errors in your example ('required' option on a widget being one).
Erland Wiencke