Does CakePHP have a form helper for html drop downs?
+4
A:
Yes, there's an explicit FormHelper::select
and array('type' => 'select')
and select fields are automatically created in certain circumstances for belongsTo relations.
deceze
2010-08-24 02:27:22
A:
The quick answer is yes:
echo $this->Form->input('fieldName2', array('type' => 'select', 'options' => $array_of_options));
If you have a helper inclusion already added to the controller, make sure you include the Form helper var $helper = array('Html', 'Javascript','Form',...);
.
Then in your views you can build forms like this:
<?php
echo $this->Form->create('ModelName', array('action' => 'nameOfAction'));
echo $this->Form->input('fieldName');
echo $this->Form->input('fieldName2', array('type' => 'select', 'options' => $array_of_options));
echo $this->Form->end(__('Submit', true));
?>
cdburgess
2010-08-24 14:48:26
A:
Just a tip to supplement the above (on point) answers: the find('list', $params) model method can often be very helpful in generating your drop down list arrays. Check out more information on that here: http://book.cakephp.org/view/449/find#find-list-810
INTJat
2010-08-24 18:37:35