I am having trouble understanding exactly what the flow of logic is for an ajax processed CActiveForm.
Context:
I am using ajax for login and registration. Login works and redirects the user to the homepage after successful login. Register works but DOES NOT redirect the user to the homepage after a successful registration. It just sits there. Sure it kinda works, but I don't understand what exactly it is doing behind the scenes.
Controller Code: (the controller/model/view code are almost exactly the same between the login and register actions)
public function actionLogin()
{
$model = new LoginForm;
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
echo CActiveForm::validate($model);
app()->end();
}
// render and nonajax handling here...
}
public function actionRegister() {
$model = new RegisterForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax'] === 'register-form')
{
echo CActiveForm::validate($model);
app()->end();
}
// render and nonajax handling here...
}
Question:
I have tried doing print line debugging to see where the code ends up going, but it seems that for ajax requests, the code ends right at app()->end();. Why is the login action redirecting me and not the register action? Where is the code that specifies where I will be redirected? I know that for the app()->end(); code, yii will raise a "onEndRequest" event in addition to exiting the app. Is this where the code for the redirect is? I have looked for anything that includes the text "onEndRequest" in my protected folder but can't find any indication of its existence.
EDIT:
I also want to send an email out after registration, but can't do so without a proper understanding of the flow of logic with this ajaxified CActiveForm. Where would I place that code? (I know how to code it up, I just don't know where to put it)