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-开发者_StackOverflow中文版>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?
you are try to register new user form, so what are you doing right, no error, when the user enter the same user name you must redirect him the the index success, and if you try to register by used user name you will face the below validation message.
精彩评论