Form select default
Permalink
I'm using the form widget documented at
http://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!
http://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!
Oh, thanks. I did read that line, but I assumed it was talking about setting the value that the user selects, rather than the initial default.
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.
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.
Just found another way to do it. Before
put
echo $form->select(...
put
if ($response == null) $response='myDefaultValue';
Another way you can use the form helper for selects:
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 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?
At first your code convert to Html then work anywhere you put 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.