cakephp : validating a login Form using $validate array
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.
Is there any reason not to use a javascript based validation? Is there a specific need to use the user model?
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!
精彩评论