mbagiella
(Mbagiella)
July 30, 2013, 8:53am
1
Hi,
I’m new on yii developpement and I have a problem to understand the mechanism of these 3 forms (dropDown,radioButton,checkbox)
When we use activeDropDown or dropDownList I don’t understand ?
And I have a little problem displaying them.
I have 2 tables :
tbl_element (HAS_MANY value)
id
type
label
tbl_value (BELONGS_TO element)
id
value
idElement
With that I cannot create a radioButton nor dropdown nor checkbox:
here the code I tried to create:
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::textField("tf_$element->id");break;
case 1: echo CHtml::textArea("ta_$element->id");break;
case 2: echo CHtml::checkBoxList("values", <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />, <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />);
case 3: echo CHtml::radioButtonList(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />);
case 4: echo CHtml::dropDownList(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,??,??);
}
endforeach; ?>
Could someone help me to fill the question mark
Thanks
yureshwar
(Yureshwar)
July 30, 2013, 9:08am
2
mbagiella:
Hi,
I’m new on yii developpement and I have a problem to understand the mechanism of these 3 forms (dropDown,radioButton,checkbox)
When we use activeDropDown or dropDownList I don’t understand ?
And I have a little problem displaying them.
I have 2 tables :
tbl_element (HAS_MANY value)
id
type
label
tbl_value (BELONGS_TO element)
id
value
idElement
With that I cannot create a radioButton nor dropdown nor checkbox:
here the code I tried to create:
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::textField("tf_$element->id");break;
case 1: echo CHtml::textArea("ta_$element->id");break;
case 2: echo CHtml::checkBoxList("values", <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />, <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />);
case 3: echo CHtml::radioButtonList(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />);
case 4: echo CHtml::dropDownList(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,??,??);
}
endforeach; ?>
Could someone help me to fill the question mark
Thanks
Hi,
In your scenario you have to use as specified below
When we use activeDropDown or dropDownList I don't understand ?
Use dropDownList. as you are trying to create the input fields manually not by database column. activeDropDown list is used if you are creating input field for database column. Remember active is meant to for databasecolumn attribute and then the value of that column.
For more info on how to use the other fields check the below link:
http://www.yiiframework.com/doc/api/1.1/CHtml/
mbagiella
(Mbagiella)
July 30, 2013, 9:25am
3
Hi,
In your scenario you have to use as specified below
When we use activeDropDown or dropDownList I don't understand ?
Use dropDownList. as you are trying to create the input fields manually not by database column. activeDropDown list is used if you are creating input field for database column. Remember active is meant to for databasecolumn attribute and then the value of that column.
For more info on how to use the other fields check the below link:
http://www.yiiframework.com/doc/api/1.1/CHtml/
So I manage to make it work but it is the "best" solution ?
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::textField("tf_$element->id");break;
case 1: echo CHtml::textArea("ta_$element->id");break;
case 2: echo CHtml::checkBoxList("ck_$element->id", '', CHtml::listData($element->values,'id','value'));
case 3: echo CHtml::radioButtonList("ra_$element->id", '',CHtml::listData($element->values,'id','value'));
case 4: echo CHtml::dropDownList("dl_$element->id", '',CHtml::listData($element->values,'id','value'));
}
endforeach; ?>
Thanks for help
yureshwar
(Yureshwar)
July 30, 2013, 9:47am
4
mbagiella:
So I manage to make it work but it is the "best" solution ?
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::textField("tf_$element->id");break;
case 1: echo CHtml::textArea("ta_$element->id");break;
case 2: echo CHtml::checkBoxList("ck_$element->id", '', CHtml::listData($element->values,'id','value'));
case 3: echo CHtml::radioButtonList("ra_$element->id", '',CHtml::listData($element->values,'id','value'));
case 4: echo CHtml::dropDownList("dl_$element->id", '',CHtml::listData($element->values,'id','value'));
}
endforeach; ?>
Thanks for help
Hi,
Use like this
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::textField("tf_".$element->id);break;
case 1: echo CHtml::textArea("ta_".$element->id);break;
case 2: echo CHtml::checkBoxList("ck_".$element->id, '', CHtml::listData($element->values,'id','value'));
case 3: echo CHtml::radioButtonList("ra_".$element->id, '',CHtml::listData($element->values,'id','value'));
case 4: echo CHtml::dropDownList("dl_".$element->id, '',CHtml::listData($element->values,'id','value'));
}
endforeach; ?>
Based on your scenario for generating dynamic form fields or input fields it is the way to create but if you want to display the name for the input field you should also use CHtml::label($element->label); before switch statement.
ahmed201
(Rifajas)
July 30, 2013, 9:47am
5
hi mbagiella, you can use activeDropDownList() when you are working with model and it manages the validation errors and show the errorCss while dropDownList() cannot…
mbagiella
(Mbagiella)
July 30, 2013, 9:18pm
6
Yeah ok and what should I change ?
like this ?
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::activeTextField("tf_".$element->id);break;
case 1: echo CHtml::activeTextArea("ta_".$element->id);break;
case 2: echo CHtml::activeCheckBoxList("ck_".$element->id, '', CHtml::listData($element->values,'id','value'));
case 3: echo CHtml::activeRadioButtonList("ra_".$element->id, '',CHtml::listData($element->values,'id','value'));
case 4: echo CHtml::activeDropDownList("dl_".$element->id, '',CHtml::listData($element->values,'id','value'));
}
endforeach; ?>
Thanks you advice
ahmed201
(Rifajas)
August 14, 2013, 4:08pm
7
mbagiella:
Yeah ok and what should I change ?
like this ?
<?php foreach ($elements as $element):
switch($element->type){
case 0: echo CHtml::activeTextField("tf_".$element->id);break;
case 1: echo CHtml::activeTextArea("ta_".$element->id);break;
case 2: echo CHtml::activeCheckBoxList("ck_".$element->id, '', CHtml::listData($element->values,'id','value'));
case 3: echo CHtml::activeRadioButtonList("ra_".$element->id, '',CHtml::listData($element->values,'id','value'));
case 4: echo CHtml::activeDropDownList("dl_".$element->id, '',CHtml::listData($element->values,'id','value'));
}
endforeach; ?>
Thanks you advice
am not sure about this use like this
CHtml::activeTextField($modelName,‘attribute’);
CHtml::activeTextArea($modelName,‘attribute’);
CHtml::activeDropDownList($modelName,‘attribute’,$value);
refer guide for more reference