Multiple Dropdownlist Same Id

I have a form several dropdownlist with the same id and I can not pass the value.

No way you could change the id, since the model does not allow me.

Can you help.

sorry for my English, thank you.

Hi my friend

You have to make multiple instances of model with like that

In your controller something like that


$m1 = new nameofModel();

$m2 = new nameofModel();

$m3 = new nameofModel();


$m1->attributes = $_POST['nameofModel'][0]

$m2->attributes = $_POST['nameofModel'][1]

$m3->attributes = $_POST['nameofModel'][2]


 $this->render('_form', array('m1' => $m1,'m2' => $m2,'m3' => $m3)

and in your _form view file something like that


 

<div class="row">

CHtml::dropDownList('nameofModel[0][yourattribute]', $m1->yourattribute, array(1=>'drop1',2=>'drop2'...));


CHtml::dropDownList('nameofModel[1][yourattribute]', $m2->yourattribute, array(1=>'drop1',2=>'drop2'...));


CHtml::dropDownList('nameofModel[2][yourattribute]', $m2->yourattribute, array(1=>'drop1',2=>'drop2'...)); 

KonApaz Thanks for your answer, I’ll do it in my project and tell you.

hi KonApaz the code no working in my project.

Check in your controller/action what is passed correctly and what does not

After of


$m1->attributes = $_POST['nameofModel'][0]

$m2->attributes = $_POST['nameofModel'][1]

$m3->attributes = $_POST['nameofModel'][2]

put this code


var_dump($m1->attributes);

var_dump($m2->attributes);

var_dump($m3->attributes);

Tell me what will display

Note: did you missed the calling of save ? In my example I haven’t the code of saving

hi:

this is message display firefox me , Undefined index: TblCaracteristicas

TblCaracteristicas is model;

thanks

Could you post the view and controller/action code ?

I have do it many times on my projects with Yii and I think I could help you :)