Yii Framework Forum: Array Value For Cactiveform Hidden Field - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Array Value For Cactiveform Hidden Field Rate Topic: -----

#1 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 28 December 2012 - 03:44 AM

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

#2 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 28 December 2012 - 04:42 AM

You have to declare the value in the model :

class MyClass extends QActiveRecord {

    public $MyArray;

0

#3 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 28 December 2012 - 06:33 AM

View Postnath-0, on 28 December 2012 - 04:42 AM, said:

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
0

#4 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 28 December 2012 - 06:56 AM

oh I am sorry CActiveRecord is CActiveRecord in fact.

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

#5 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 28 December 2012 - 09:20 AM

View Postnath-0, on 28 December 2012 - 06:56 AM, said:

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
0

#6 User is offline   Hyprion 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 07-October 09
  • Location:Netherlands

Posted 28 December 2012 - 09:28 AM

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

#7 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 28 December 2012 - 09:57 AM

View PostHyprion, on 28 December 2012 - 09:28 AM, said:

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
0

#8 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 28 December 2012 - 12:25 PM

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

#9 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 01 February 2013 - 12:27 AM

Thanks It works :)


View Postseenivasan, on 28 December 2012 - 12:25 PM, said:

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.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users