rigel
(Rigel Deshmukh)
December 28, 2012, 8:44am
1
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.
nath-0
(Nathalie Chabert)
December 28, 2012, 9:42am
2
You have to declare the value in the model :
class MyClass extends QActiveRecord {
public $MyArray;
rigel
(Rigel Deshmukh)
December 28, 2012, 11:33am
3
I have declared it in
class MyClass extends CActiveRecord {
public $MyArray;
I get an Error Parameter string needed
What is Q activeRecord Didnt find it in Class reference
nath-0
(Nathalie Chabert)
December 28, 2012, 11:56am
4
oh I am sorry CActiveRecord is CActiveRecord in fact.
But can you explain a bit about what you want do to?
rigel
(Rigel Deshmukh)
December 28, 2012, 2:20pm
5
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
sx9
(Sx9)
December 28, 2012, 2:28pm
6
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?
rigel
(Rigel Deshmukh)
December 28, 2012, 2:57pm
7
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
seenivasan
(Chellamnivas)
December 28, 2012, 5:25pm
8
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.