My form have select option and check box field. i m not getting the values of those fields.
<?php echo $form->dropDownList($model,‘vehicle_type’,array(’’=>‘select’,1=>‘Tempo’,2=>‘Jeep’,3=>‘Lorry’,4=>‘Bus’,5=>‘Tipper’,6=>‘Tanker’,7=>‘Tractor’,8=>‘Pick up van’));?>
when select the options it will display 1,2 like .how do change it.
When you select an option from the dropDownList, the returned value is the first part of the array assignment.
In the above, when you select ‘Tempo’ you will get a ‘1’ back. You will need to translate that ‘1’ back to ‘Tempo’ elsewhere in your code. What I usually do is create a couple of function in the model:
public function getListLabel($id) {
$list = $this->getDataList();
return $list[$id];
}
public function getDataList() {
return array(
1=>'Tempo',
2=>'Jeep',
3=>'Lorry',
4=>'Bus',
5=>'Tipper',
6=>'Tanker',
7=>'Tractor',
8=>'Pick up van'
);
}
This way you can add another vehicle type at any time.
The ‘empty’ option may not be in the right place, or exact right code. This is off the top of my head, but I have seen it in other postings/Google searches.
I have not used the CheckBoxList, so I can’t help with that.
Yes the dropDown WILL return a number Tempo=1, so 'vehicle_type’will store a ‘1’. To display ‘Tempo’ instead, as I indicated, will will need to manually retrieve the ‘label’;