0

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?

user1929946
  • 2,453
  • 2
  • 15
  • 17
  • 1
    What do you mean by *redhand*? By the way, md5 is weak. [Use something stronger](http://stackoverflow.com/a/401684/569101) (like sha1 or bcrypt). – j0k Dec 26 '12 at 16:58
  • after the request comes and before it goes to the database. In the meantime want I encode it. – user1929946 Dec 26 '12 at 17:12

1 Answers1

1

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();
Leprosy
  • 1,085
  • 4
  • 14
  • 36
  • isnt there are easier solution out there? A time ago, it was easier just edit the _POST array. And for example, there is an "auto increment" ID, I dont need it neither, but then validator would fail – user1929946 Jan 04 '13 at 13:23
  • 1
    Well, in frameworks you can always hack your way in order to implement things. This is just a "Symfony" way to achieve this. :P – Leprosy Jan 07 '13 at 15:37