user1929946
user1929946

Reputation: 2503

Symfony 1.4 what if I want a form field to be changed something through?

Lets suppose I have a user registration form. Since the password must be stored md5 encoded, the best idea would be to convert it in redhand, but it looks request is read only. How to change a form field during processing?

Upvotes: 0

Views: 293

Answers (1)

Leprosy
Leprosy

Reputation: 1135

You can use a custom Validator for the form. Create a class like this:

<?php

class encodeValidator extends sfValidatorBase
{
  /**
  * @see sfValidatorBase
  */
  protected function doClean($value)
  {
     return md5($value); //md5 can be replaced with another encoding method
  }
}

Next, when you create your form, add the custom validator you created, like this:

$this->setWidget('field_name', new sfWidgetFormInputText());
$this->validatorSchema['field_name'] = new encodeValidator();

Upvotes: 1

Related Questions