At the first load of my app, there will be a gridview like this
4536
then, when user click add, it will renderpartial a form using ajax like this
4533
there is validation, so user cannot create until the form is correct validated
some error messsage will appear
4534
but sometimes when user click create without input, it goes to the true url, leave my grid page
4535
what should i add please to my code to prevent this thing?
here’s my controller code
public function actionFormAdd($idhotel)
{
$this->layout = '//layout/ajax';
$model=new Promo;
$this->performAjaxValidation($model);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Promo']))
{
$model->attributes=$_POST['Promo'];
if($model->save())
$this->redirect(array('hotel/view/id/'.$model->hotelid.'/#promocodes'));
}
$this->render('_tab_ajax_add',array(
'model'=>$model,
'idhotel'=>$idhotel,
), false, true);
}
I’ve tried to add this but no result
$cs = Yii::app()->clientScript;
$cs->reset();
$cs->scriptMap = array(
'jquery.js' => false, // prevent produce jquery.js in additional javascript data
);
Yii::app()->clientScript->registerCoreScript('jquery');
_tab_ajax_add
<div>
<?php $this->renderPartial(’_add_form’,array(
'model'=>$model,
'hotelid'=>$idhotel,
)); ?>
</div>
in _add_form I define
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'promo-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'clientOptions' => array(
'validateOnSubmit' => true),
));
?>
...
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array("class"=>"small button"));?>