I have piece of code like below, and I want to find Login error code (eg:self::ERROR_USERNAME_INVALID) if any error exist, to show user a proper message through ajax.
$model=new LoginForm;
$model->username = $_POST['username'];
$model->password = $_POST['password'];
$model->rememberMe = ($_POST['remember'] == 'on') ? TRUE : FALSE;
if(isset($_POST['isAjax']))// Codes For Ajax Login (Modal Login)
{
if($model->validate() && $model->login())
{
$result = 'enter';
}
else if(//here I want that code to know which error occurred when user tried to login)
{
}
}
Could you help me, how I can reach these error code in my site controller?
Perhaps you could add an attribute to your LoginForm model and set it after validation:
class LoginForm extends CFormModel
{
public $loginErrorCode;
...
public function validate()
{
// If validation fails, update $this->loginErrorCode here
}
}