views:

83

answers:

2

Can Any One help me to Validate a login Form in cakePHP?
I need to validate the login form just like how we validate a registration form using $validate array in Model.

EDIT : Since I am using Auth Component for Authentication. It directly goes to login action in Auth Component with out validating from the user model.So it will only show the error message as "invalid username/password" even though i simply press the login button without giving any username or password.I need to show invalid username by the side of the username text box if the username left blank

Any help will be appreciated.

A: 

Is there any reason not to use a javascript based validation? Is there a specific need to use the user model?

RaScoop
A: 

It would be helpful to see your code. However, from the sounds of it, you want to show the username they attempted to use. Keep in mind there is nothing magic about the view and the variables. So to show the email address they attempted to use you could just put it right back in the text field (or put it anywhere you want). I will show you both options:

// back in the text field - login function in users_controller.php
function login() {
   $this->set('username', $this->data['User']['username']);
}

// to echo it outside of the text box
function login() {
   $this->set('uname', $this->data['User']['username']);
}

Then in the view, you would do something like:

<?php
  if (!empty($uname)) {
     echo $uname;
  }
?>

Happy coding!

cdburgess
@cdburgess : i need to show the error message as in gmail login form.
RSK