Here is what I am trying to do:
There is a user registration form on a page. After the registration is complete, display a message "you are successfully registered" replacing the registration form and without loading the whole page.
I want to invoke the ajax action in a controller action:
public function actionRegister()
{
$form=new UserRegForm;
if(isset($_POST['UserRegForm']))
{
$form->attributes=$_POST['UserRegForm'];
if($form->validate())
{
$user = new User;
$user->attributes = $form->attributes;
$user->password = md5($user->password);
$user->save();
$this->actionAjax101(); // registration is successful, let's replace the form with a success msg
// form inputs are valid, do something here
return;
}
}
$this->render('_RegForm',array('model'=>$form));
}
public function actionAjax101()
{
$this->renderPartial('ajax101', array(), false, true);
}
This is the ajax101.php view file:
<?php
echo 'the user has been successfully registered';
?>
The result is a white screen with only ‘the user has been successfully registered’. Where do I put array(‘update’=>’#forAjaxRefresh’) in a controller action?
I know it may be an wrong approach to solve this problem. Can you help?
Thank you!