I created app with yii and i needed to load view form in Fancy-box so i did that but my problem when i clicked on submit button , from redirected me to controller action without validated form . How to validate form with out redirect , mean validate inside Fancy-box ?
public function actionCreate()
{
$model=new Section;
if(isset($_POST['Section']))
{
$model->attributes=$_POST['Section'];
if($model->validate())
//// Do Som code here
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
public function actionCreate()
{
$model=new Section;
$this->performAjaxValidation($model); //This is the added line.
if(isset($_POST['Section']))
{
$model->attributes=$_POST['Section'];
if($model->validate())
//// Do Som code here
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
I’m sorry but I’m not familiar with the fancybox, so I don’t know how to render CActiveForm correctly in it. It looks like the script for the active form is not in effect.
Did you check the script in your developer tool of the browser?
ublic function actionCreate()
{
$model=new Section;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);//You have enabled ajax validation. You have to uncomment this line.
if(isset($_POST['Section']))
{
$model->attributes=$_POST['Section'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
if(Yii::app()->request->getIsAjaxRequest())
echo $this->renderPartial('_form',array('model'=>$model),true,true);//This will bring out the view along with its script.
else $this->render('create',array(
'model'=>$model,
));
}
then it breaks. When I submit the page, it’s not rendered in as a normal page instead of inside EFancyBox. Bizarrely, this is only happening when I remove the “echo $form->error()” for the “email” attribute.