Form select default
Permalinkhttp://documentation.concrete5.org/tutorials/how-to-use-the-form-wi...
to display a 'select' input field. I'd like to specify an initial default other than the first item. I know how to do this in HTML, but not via this widget.
Help!
I note that the widget can set the default to match whatever comes out of the database.
I didn't know I could mix in my own HTML; that should do it.
echo $form->select(...
put
if ($response == null) $response='myDefaultValue';
The nice thing is, the form control will automatically select whichever value has been stored, instead of having the write ternary operators on each select option to determine that.
The link you posted shows how to use it this way correctly.
I realized I've been trying to answer the wrong question all along though. You needed to set the initial selected item to something other than the first one. How did you end up doing it?
"The form widget handles setting the selected attribute."
Its ok to code your form element in HTML. You will notice people use both the form widget at times, and at other times they code it themselves. It just depends on the need. For example, a block that has a select element needs to have the whatever value was saved to the database display as the selected value. To do this you have to code the element normally, then add ternary operators to each option in the select that will output 'selected' to the tag if its value matches whats saved in the database.