how to pass cactive form obect to ajax page

My index page code look like(index.php):


<?php $form=$this->beginWidget('CActiveForm', array(

				  'id'=>'policy-registration-form',

				  'enableClientValidation'=>true,

				  'clientOptions'=>array(

				  'validateOnSubmit'=>true,

				  ),

));

?>

 <label class="small" for="noapplicants">Number of applicants</label>

<?php

$static = array('1'=>1,'2'=>2,'3'=>3,'4'=>4,'5'=>5,'6'=>6,'7'=>7,'8'=>8,'9'=>9,'10'=>10,);


echo $form->dropDownList(

		  $PolicyFamilyApplicant,

		  'applicants_count',

		  $static ,

		  array('empty'=>Yii::t('fim','Please Select'),

				'onchange'=>CHtml::ajax(array(              

					  'type'=>'POST',							       

					  'url'=>array("policyFamilyDetails/applicantList"),

					  'data'=>array('applicant_count'=>'js:this.value',

					  'applicant_list'=>'js:$(".applicants").length',

					  ),  

		  'update'=>'.applicant_list'

		  )),

));

?>

<div id="applicant_1" class="applicants">

<h3>Main Applicant</h3>

<div class="halfCol float">

<div class="item">

 <label for="firstname" class="xsmall">First Name</label>

 <?php 

    echo $form->textField($PolicyFamilyDetails,'first_name',array('class'=>'medium')); 

 ?>

</div>

</div>

<?php $this->endWidget(); ?>



And when i change the dropdown list value, i need to get the text field for the first_name that much time.

And my applicant_list.php file look like


<?php for ($i=$applicant_list;$i<$applicant_count;$i++) {?>

    <div id="applicant_<?php echo $i+1;?>" class="applicants">

    <div class="item">

      <label for="firstname" class="xsmall">First Name</label>

      <?php 

        echo $form->textField($PolicyFamilyDetails,'first_name',array('class'=>'medium')); 

      ?>

    </div>

    </div>

<?php } ?>  



And the controller looks like


<?php

class PolicyFamilyDetailsController extends Controller

{

   public function actionIndex()

   {

     $PolicyFamilyDetails=new PolicyFamilyDetails;

     $data['PolicyFamilyDetails']=$PolicyFamilyDetails;

     $this->render('index',$data); 

   }

   public function actionapplicantList()

   {

      $data=array();

      $PolicyFamilyDetails=new PolicyFamilyDetails;

      $data['PolicyFamilyDetails']=$PolicyFamilyDetails;

      $data['applicant_list']=$_POST['applicant_list'];

      $data['applicant_count']=$_POST['applicant_count'];

      $this->renderPartial('applicant_list',$data);

   }

}

?>

And when I change the dropdown value, i am getting an error like:

Fatal error: Call to a member function textField() on a non-object in /var/www/html/dev3/protected/views/policyFamilyDetails/applicant_list.php on line 10

its due to the $form object. How can I pass $form object in index.php to application_list.php?

Hello and welcome to the forum. Can you please edit your post and format your code?

You may use the <> button in the editor toolbar, or one of the styles in the dropdown on the topleft.

I pasted the indented code. And when i try to edit, its not possible.

wrap you code as following

\[code\]… code …\[/code\]

remove the black slashes (\) i added just so you could see the tags

I formatted my code

Well you are passing an array to your view so you can use only that array as external variable. Or pass directly the variables you seem to want in your view:


public function actionapplicantList()

{

    $data=array();

    $PolicyFamilyDetails=new PolicyFamilyDetails;

    $applicant_list = $_POST['applicant_list'];

    $applicant_count = $_POST['applicant_count'];

    $this->renderPartial('applicant_list', array('PolicyFamilyDetails' => $PolicyFamilyDetails, 'applicant_list' => $applicant_list, 'applicant_count' => $applicant_count));

}

sorry sir…i didn’t get your point because i am new to yii… and i changed accordingly…but still getting the same error

No it’s me who hasn’t read well your code and your description of the problem.

You’ve said very well

You’re right. But I personally don’t have a clue.