tags:

views:

58

answers:

3

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
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
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