Cakephp select list of numbers with corresponding values -
i have select list generate :
echo $this->form->input('number_of_vehicles', array('empty' => 'select...', 'type' => 'select', 'options' => range(1, 10, 1)));
now generates nice numbered select list 1 10, incremented 1...great. option value starts @ 0 eg.
<select name="data[contact][number_of_vehicles]" id="contactnumberofvehicles"> <option value="">select...</option> <option value="0">1</option> <option value="1">2</option> <option value="2">3</option> <option value="3">4</option> <option value="4">5</option> <option value="5">6</option> <option value="6">7</option> <option value="7">8</option> <option value="8">9</option> <option value="9">10</option> </select>
how value correspond text between option tags. can circumvent problem javascript not ideal. , of course, using normal html normal php easy.
what cake way this?
bear in mind cakephp php or extension of php if want that. options takes php array functions there long output looking for.
for specific need, suggest array_combine
php function. can set follows:
echo $this->form->input( 'number_of_vehicles', array( 'empty' => 'select...', 'type' => 'select', 'options' => array_combine(range(1,10,1),range(1,10,1)) ) );
that give following array cakephp magically include in form:
array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 )
and cakephp generate following html code:
... <option value="">select...</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> ...
good luck!
Comments
Post a Comment