Array Value For Cactiveform Hidden Field

Hi




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

	'id'=>'advertisement-form',

	'enableAjaxValidation'=>false,

	'enableClientValidation'=>true,

	'method'=>'post',

	'clientOptions' => array(

          'validateOnsubmit'=>true,

	     		

              ),

)); ?>


<?php echo $form->hiddenField($model,'MyArray'); ?> 


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




‘MyArray’ is an array value. How can i implement as hidden fields takes only string value.

You have to declare the value in the model :




class MyClass extends QActiveRecord {


    public $MyArray;



I have declared it in




class MyClass extends CActiveRecord {


    public $MyArray;



I get an Error Parameter string needed

What is QactiveRecord Didnt find it in Class reference

oh I am sorry CActiveRecord is CActiveRecord in fact.

But can you explain a bit about what you want do to?

Hi I have a hidden field in form that POST an array value. But the problem is in CActiveFrom hidden you can pass a string and not array value

You’d have to use your own function since (like you said) hiddenfield only supports strings.

Just out of curiosity, what would be the expected output of the function?

Well I want to send an array to the controller and save it in my mongodb as array

Dear Friend

Check whether the following is helpful.

In your controller actionCreate or actionUpdate method




public function actionUpdate()

	{

		$model=$this->loadModel($id);

		$model->MyArray=implode(",",$model->MyArray);




		if(isset($_POST['Advertisement']))

		{

			$model->attributes=$_POST['Advertisement'];

			$model->MyArray=explode(",",$model->MyArray);

			print_r($model->MyArray);

			//$model->arr=implode(",",$model->arr);//here if validation fails for other attributes, kindly ensure that it is again converted to string.

			//if($model->save())

				//$this->redirect(array('view','id'=>$model->id));

		}

		$this->render('create',array(

			'model'=>$model,

		));

	}



Regards.

Thanks It works :)