Hello
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 ?
if(isset($_POST[‘User’]))
{
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect('index');
}
Please advice
softark
(Softark)
August 23, 2014, 11:28am
#2
How do you write your ajax submit button?
I think you could write ‘success’ option to update the view.
http://www.yiiframework.com/doc/api/1.1/CHtml#ajax-detail
i written below code inside my view:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'clients-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'successCssClass' => 'success',
),
'htmlOptions'=>array(
'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>
<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')); ?>
</div>
<?php $this->endWidget(); ?>
after completed submission it redirect to index page however i have to display success message and reset current form.
vilochane
(Vilochane)
August 25, 2014, 6:05am
#4
i written below code inside my view:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'clients-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'successCssClass' => 'success',
),
'htmlOptions'=>array(
'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>
<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')); ?>
</div>
<?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' => ));
array(
"response"=>"something",
"something"=>"something",
)
echo "something" if an array use CJSON::encode(array());
}