I use Doctrine:

User:
  columns:
    username:        { type: string(255), unique: true }
    password:        { type: string(255) }
    ip:              { type: string(255) }

This generated me new form:

username: 
password:
ip:

How can i make confirm password and get the IP address in hidden input?

I will:

username:
password:
confirm password:

and in mysql database will username, password and IP ($_SERVER['REMOTE_ADDR'];) How can i it make in Symfony 1.4?

THX!

@@@@@@@

added:

i make:

  $user = $this->form->getObject();
  $user->setPassword(sha1($user->getPassword()));
  $user->setIp($_SERVER['REMOTE_ADDR']);
  $user = $form->save();

setPassword doesn't work, but setIp good work.

Accepted Answer

You may remove fields by setting in the configure() method of your form:

unset($form['ip'])

And add a confirm password field by:

    $this->widgetSchema['password']     = new sfWidgetFormInputPassword();
    $this->widgetSchema['password2']    = new sfWidgetFormInputPassword();
    // Don't print passwords when complaining about inadequate length
    $this->setValidator( 'password', new sfValidatorString(array(
        'required' => true,
        'trim' => true,
        'min_length' => 6,
        'max_length' => 128
        ));
    $this->validatorSchema['password2'] = clone $this->validatorSchema['password'];        

    $this->mergePostValidator(new sfValidatorSchemaCompare(
        'password', sfValidatorSchemaCompare::EQUAL, 'password2',
        array())
    ));

You may add the ip in your actions.class.php:

if ($request->isMethod('post')) {
  $this->form->bind($request->getParameter('yourformprefix'));
  if ($this->form->isValid()) {
    $user = $this->form->getObject();
    $user->setIp($_SERVER['REMOTE_ADDR']);
    $user->save();
  }
}

A small note: I strongly recommend using the existing plugins (doAuth / sfDoctrineGuardPlugin) if you're planning to do this kind of work.

Written by Arend
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki