By sumgai on
I'd like to create a form element that is a 'select', but that has a 'value' that isn't the same as the option's display string and also to be able to set the "selected" option.
So, rather than just:
<option>red</option>
I'd like to have elements like:
<option value='red' selected='selected'>The Color Red</option>
I've searched through the form module code, but don't see anything at all about it.
Any help would be mucho appreciado!
Mitch
Comments
#options value
When you setup a select field one of the values is '#options' which is set to an array of values to select from.
The format for this array is
or using your example
Thanks and how about profiles?
Is there also a way to do this in the profile module? It isn't obvious what code I would insert in the textbod that the profile module provides for entering the options for a select.
Thank you again!
Mitch
For profiles, no way that I know of
I believe for the profile module the displayed and stored value are always the same.
One last question...
Is there a way to specify 'selected' for one of the options in the select?
You've been a great help! Many Thanks!
Mitch
Set #default_value
If you set #default_value for the select list it will be used as the initial/existing value.
Thank You! Thank You!
You've been a tremendous help!
hook_elements
Hi sumgai
You could use hook_elements to add your own fields to the profile module although change the existing one would involve chaning the code...
http://api.drupal.org/api/HEAD/function/hook_elements
Dave
Use code like the following
Use code like the following to create a dynamic list of options:
$options[$term->tid] is the value that will be returned in the form
www.johnstonwebsolutions.com/we_install_modify_and_maintain_drupal_web_s...
selected value
So now you have list of items, how to put 'selected' on currently selected on this jump menu- instead of having the predifined selected. http://drupal.org/node/91924