Hi everybody
My title is maybe not really clear…
so let me explain my problem :
I have a form (widget active form) in my main page. on this form the ajax validation works fine.
but, depending of certain option of this form, (for exemple check a radioButton), an additionnal part of the form appears.
my code :
//start of the form
$form=$this->beginWidget('CActiveForm', array(
'id'=>'evenement-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true)
)); ?>
// some input
...
// my radioButton with my ajax event.
<?php
echo $form->radioButton($eventForm, 'comboGestionnaireValue', array(
'value'=>'2',
'uncheckValue'=>null,
'onChange'=>CHtml::ajax(array(
'type'=>'POST',
'url'=>@Yii::app()->createUrl('admin/UpdateAjaxFormGestionnaire'),
'data' => array('form'=>serialize($form)),
'update'=>'#gestionnaireCell')) )); ?>
//the rest of my form.
...
So when I check the combobox, it will called the action in my controller.
this is the action :
public function actionUpdateAjaxFormGestionnaire()
{
$eventForm = new eventForm;
$form = $_POST['form'];
if(isset($_POST['ajax']) && $_POST['ajax']==='evenement-form')
{
echo $form::validate($eventForm);
Yii::app()->end();
}
$this->renderPartial('_ajaxContentFormGestionnaire', array(
'form'=>$form,
), false, true);
}
And finnaly my partial view rendered :
<?php
$form = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $form);
$form = unserialize($form);
$eventForm = new EventForm;
?>
<div class="row">
<?php echo $form->labelEx($eventForm,"Nom"); ?>
<?php echo $form->textField($eventForm,"Nom",array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($eventForm,'Nom'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($eventForm,'Prenom'); ?>
<?php echo $form->textField($eventForm,'Prenom',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($eventForm,'Prenom'); ?>
</div>
...
and I want to have an ajax validation on this rendered part…
and a validation when I press the submit button before to store data in the DB to keep the input field filled if there is an error.
there is a lot of post about this, but I didn’t find any solution.
do you have any idea? thanks.