i'm new to symfony and i'm having the following issue creating login logic for application:
1) I have a form which is loaded by a slot in the layout.php file, the form contains a 'User' object, with only 2 properties: 'user_name'and 'password', and validation is taken care by symfony validator framework (both fields have 'required' validator set as you migh have guessed)
index page is accesed by action:
public function executeIndex(sfWebRequest $request)
{
$this->form = new UserFormLogin();
}
The form is loaded by something like this in the layout file:
2) I have a login action, which performs validation, here's the relevant code:
protected function processLoginForm(sfWebRequest $request, sfForm $form)
{
form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
...Some code to retrieve from db, check credentials etc...
}
else
{
$this->redirect('users/index');
}
}
public function executeLogin(sfWebRequest $request){
$this->forward404Unless($request->isMethod(sfRequest::POST));
$this->form = new UserFormLogin();
$this->processLoginForm($request, $this->form);
}
3) All the above so (theoretically) when a user inputs non-valid credentials returns to index and shows error messages... but instead of getting the expected 'username is required' or something like that, it gives me the next error: "An object with the same "user_name" already exist.
Any ideas why is that? please help me, what i'm missing?
user_name
? - Darmen Amanbayev