Symfony-注册系统-确认密码和隐藏的输入

| 我使用学说:
User:
  columns:
    username:        { type: string(255), unique: true }
    password:        { type: string(255) }
    ip:              { type: string(255) }
这产生了我新的形式:
username: 
password:
ip:
如何在隐藏的输入中输入确认密码并获取IP地址? 我会:
username:
password:
confirm password:
并在mysql数据库中输入用户名,密码和IP($ _SERVER [\'REMOTE_ADDR \'];) 我如何在Symfony 1.4中进行制作? 谢谢! @@@@@@@@ 添加: 我做:
  $user = $this->form->getObject();
  $user->setPassword(sha1($user->getPassword()));
  $user->setIp($_SERVER[\'REMOTE_ADDR\']);
  $user = $form->save();
setPassword不起作用,但是setIp很好。     
已邀请:
        您可以通过在表单的configure()方法中进行设置来删除字段:
unset($form[\'ip\'])
并通过以下方式添加确认密码字段:
    $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())
    ));
您可以在您的actions.class.php中添加IP:
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();
  }
}
注意事项:如果您打算进行此类工作,我强烈建议您使用现有的插件(doAuth / sfDoctrineGuardPlugin)。     

要回复问题请先登录注册