views:

104

answers:

2

Currently, my login form looks like this,

class LoginForm extends BaseFormPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'login_id' => new sfWidgetFormInput(), 
      'pwd' => new sfWidgetFormInputPassword() 
    ));

    $this->widgetSchema->setLabels(array(
     'login_id'=>'Login Id',
     'pwd'=>'Password'
    ));

    $this->widgetSchema->setNameFormat('member[%s]');

    $this->setValidators(array(
      'login_id' => new sfValidatorPropelChoice(array('model' => 'Member', 'column' => 'login_id', 'required' => true)), 
      'pwd' => new sfValidatorPropelChoice(array('model' => 'Member', 'column' => 'pwd', 'required' => true))
    ));

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }


  public function getModelName()
  {
    return 'Member';
  }

}

But this is a wrong implementation, because sfValidatorPropelChoice only ensures the user enters a value that does exist in the column. This means if the database contains the following rows,

login_id | pwd
john, 12345
peter, 67890

A user using john and 67890 to login will succeed. My question is that, which validator should I use to correct the problem?

+1  A: 

You should use your own post-validator, because you are trying to validate 2 form fields at once. Or you could use sfGuardPlugin and forget this question.

develop7
+1  A: 

There is no nice way to do this job. In sfGuard form validates incoming data and after use form data to sign in user, here is sample

if ($this->form->isValid()) {
$values = $this->form->getValues();
$this->getUser()->signin($values['user']); }

I don't know maybe [1] sfValidatorAnd do something like that, but login proccess very importand thing in web application so, you should handle with your code this proccess.

http://www.symfony-project.org/forms/1_2/en/B-Validators#chapter_b_sub_sfvalidatorand

metoikos