Reputation: 117
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)
Upvotes: 1
Views: 656
Reputation: 6866
I ran into this same problem in our Doctrine 1.2 application. In my case, the fix ended up adding this workaround to the record's merge()
method:
$this->email = trim($this->email);
if ($this->email == '') {
$this->email = null;
}
Upvotes: 1
Reputation: 4881
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));
Upvotes: 0