سؤال

I am working with Symfony 1.4 and Doctrine. I have a model A with an email field. The form of A displays an input in which the user should insert the email correctly. But as everybody knows, sometimes they don't do it.

To fix this I have inserted an extra field in the model (and in the form), called *repeat_email* to prevent the misspellings. Then, in the validation process, after validating all the fields, i use a global validator to compare the data of the two fields.

This works, but I don't want to have the email stored two times in the database (I don't want the *repeat_email*). Is there any mechanism to use it in the validation process, but not to store it in the database?

Thanks,

هل كانت مفيدة؟

المحلول

Remove repeat_email field from the model schema, and configure your form like this:

    //email widget and validator are configured in the base class

    $this->widgetSchema['repeat_email'] = new sfWidgetFormInput();
    $this->validatorSchema['repeat_email'] = clone $this->validatorSchema['email'];

    $this->widgetSchema->moveField('repeat_email', 'after', 'email');

    $this->mergePostValidator(new sfValidatorSchemaCompare('email', sfValidatorSchemaCompare::EQUAL, 'repeat_email', array(), array('invalid' => "Emails don't match")));

نصائح أخرى

the mistake was probably to add an additional field in the model. You only need it in the form.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top