June 22, 2009, 1:18pm
Just a quick question. I'm using ajax to submit my forms which are working great, however if a user has been afk from the keyboard for a while and was filling out a form, then return and press submit the login redirect renders in the response div rather then the whole page. Is there a way to stop this? - I tried mucking around in the CWebUser class but had no luck…
June 22, 2009, 1:37pm
the easiest way seems to be to look for a specific element (e.g. the login form) inside your ajax response.
Take a look at this:
June 22, 2009, 11:04pm
Thanks for the reply.
Currently I'm using the following code;
<?php echo CHtml::ajaxSubmitButton($update ? 'Save' : 'Create','',array('type'=>'Post','update'=>'#upr',)); ?>
for the submit button, then in the controller;
after a successfull result.
June 23, 2009, 3:17am
I handled this by utilizing the jquery form plugin to send the ajax request when the form was submitted.
I then called a custom controller to handle the actions and return some json data for sucess or failure.
On success it sends the redirect url along in the response.
for failure i return the errors generated allowing me to put error messages with the field that was wrong and display messages for non field problems.
June 23, 2009, 10:16am
if you want to use the solution presented by the page i linked you can do something like the following.
Button (note: using the success callback disables 'update' - see documentation):
<?php echo CHtml::ajaxSubmitButton($update ? 'Save' : 'Create','',array('type'=>'Post','success'=>'successCallback',)); ?>
$loginUrl = $this->createUrl(Yii::app()->getUser()->loginUrl);
if($("#nigolFrm", data).size() > 0)
// Register the script within yii
The code is just an example, it's not tested.
You should also keep the form's error messages in mind as rfenner pointed out!
Maybe this helps a little bit