Ajax Submit Success Validation


Ref. http://www.yiiframework.com/doc/api/1.1/CActiveForm

if after ajax submit we do not need to redirect page then how to display success message and hide all error messages?







Please advice

How do you write your ajax submit button?

I think you could write ‘success’ option to update the view.


i written below code inside my view:

<?php $form=$this->beginWidget('CActiveForm', array(






                'successCssClass' => 'success',



            'onsubmit'=>"return false;",/* Disable normal form submit */


        'ajaxSubmitOptions' => array(

            'success' => 'alert("hi")', 


)); ?>

<div class="row">

		<?php echo $form->labelEx($model,'client_name'); ?>

		<?php echo $form->textField($model,'client_name',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($model,'client_name'); ?>


<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class' => 'btn  btn-md sr-btn-success pull-left  margin-top-zero margin-bottom-zero')); ?>


<?php $this->endWidget(); ?>

after completed submission it redirect to index page however i have to display success message and reset current form.

In your controller action remove the redirect code and echo or use an array to get the response to the view. Plus you’re not using an ajax submit button in your view

echo CHtml::ajaxsubmitButton()

 if ($model->save()){

               /* remove this code*/

                $this->redirect(array('view', 'id' => ));





              echo "something" if an array use CJSON::encode(array());