Validation Ajax Sur Un Formulaire Ajouter Grace A Un Ajax Event Et Un Renderpartial.

Salut a tous !

Mon titre n’est peut etre pas tres clair :)

Donc, laissez moi vous expliquer mon problème

J’ai un formulaire(widget active form) dans ma page principale. Sur celui ci les validation ajax fonctionne très bien. Mais, en fonction de certaines options de mon formulaire, (par exemple cocher un radioButton), une partie additionnelle du formulaire apparait grace a un event ajax.

mon 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.

...



Donc, quand je coche le radiobutton, cela va appeller mon action de mon controller. voici l’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);        

    } 



Et enfin la partir du formulaire ajoutée. (celle sur laquelle je n’ai pas de validation ajax.)




<?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>


...




Et je desire donc une validation ajax sur cette partie supplementaire.

ainsi qu’une validation lorsque je clique sur le bouton envoyer avant de stocker les informations dans la base de donnee afin de garder les champs garnis si il y a une erreur.

Il y a pas mal de post sur le sujet mais je n’ai toujours pas reussi a trouver la solution qui corrigerait mon problème.

auriez vous une idée sur le sujet?

Merci d’avance.

Vincent.