Skip to content
Advertisement

cakePHP value for empty option

is there a way to pass a value for the empty option in a select dropdown generated by the FormHelper?

I’m creating an input like this:

echo $this->Form->input('supplier_id', array('empty'=>true));

with values supplied automatically from the controller like this

JavaScript

and the select box is created like this:

JavaScript

but I would like the first option (the empty one) to have a value of 0 instead of ” is it possible? or should I instead modify the $suppliers array in the controller with something like

JavaScript

and remove the empty option from the FormHelper input?

Advertisement

Answer

Using the verbose array syntax you can chose any value for empty:

JavaScript

See http://www.dereuromark.de/2010/06/23/working-with-forms/

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement