Well, I'm back again, and this time I have a question about attributes for select options in a form. I have a form that has a select element (multi-select) that lists users. The form is for some admin settings for a module. When the form is displayed, I need to be able to highlight specific options in the list based on data returned from a query. I've been looking all day, and haven't been able to figure it out. There is the #attribute key, but it is for the field as whole (at least as far as I can determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would appreciate it.
Thanks.
Steve
Make the #default_value an array of the keys of the options you want selected.
$form['item'] = array( '#type' => 'select', ... '#options' => array of all options, '#default_value' => array of keys from above options. ... );
Check http://api.drupal.org/api/file/developer/topics/forms_api_reference.html /5#default_value for more info.
Greg
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Steve Edwards Sent: Tuesday, November 27, 2007 8:25 PM To: support@drupal.org Subject: [support] How to add "selected" attribute to select list <option>tag
Well, I'm back again, and this time I have a question about attributes for select options in a form. I have a form that has a select element (multi-select) that lists users. The form is for some admin settings for a module. When the form is displayed, I need to be able to highlight specific options in the list based on data returned from a query. I've been looking all day, and haven't been able to figure it out. There is the #attribute key, but it is for the field as whole (at least as far as I can determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would appreciate it.
Thanks.
Steve
Hmmm, getting closer, but I can't seem to get it to work. No matter what I try, I can't get it to select anything.
Here is what my select list looks like (in HTML)
<option value="1">Name 1 <option value="2">Name 2 <option value="3">Name 3 <option value="4">Name 4 <option value="5">Name 5
The value is the user's uid. number That being the case, what would i use for #default_value? I've tried things like
'#default_value' => array(1 => 'Name 1') '#default_value' => 1 '#default_value' => 'Name 1'
but I can't get any of them to work. Any ideas?
Thanks.
Steve
Greg Holsclaw wrote:
Make the #default_value an array of the keys of the options you want selected.
$form['item'] = array( '#type' => 'select', ... '#options' => array of all options, '#default_value' => array of keys from above options. ... );
Check http://api.drupal.org/api/file/developer/topics/forms_api_reference.html /5#default_value for more info.
Greg
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Steve Edwards Sent: Tuesday, November 27, 2007 8:25 PM To: support@drupal.org Subject: [support] How to add "selected" attribute to select list
<option>tag
Well, I'm back again, and this time I have a question about attributes for select options in a form. I have a form that has a select element (multi-select) that lists users. The form is for some admin settings for a module. When the form is displayed, I need to be able to highlight specific options in the list based on data returned from a query. I've been looking all day, and haven't been able to figure it out. There is the #attribute key, but it is for the field as whole (at least as far as I can determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would appreciate it.
Thanks.
Steve
Hi Steve,
Are you getting the entries out of a database or are you setting them straight off with static values?
You haven't got a closing tag on your option tag in your html i.e. "</option>" so this could be the problem for starters.
If you send the section of code you are talking about it's probably easier to work out.
Sarah
----- Original Message ----- From: Steve Edwards killshot91@comcast.net Date: Wednesday, November 28, 2007 3:04 pm Subject: Re: [support] How to add "selected" attribute to select list <option>tag To: support@drupal.org
Hmmm, getting closer, but I can't seem to get it to work. No matter what I try, I can't get it to select anything.
Here is what my select list looks like (in HTML)
<option value="1">Name 1 <option value="2">Name 2 <option value="3">Name 3 <option value="4">Name 4 <option value="5">Name 5
The value is the user's uid. number That being the case, what would i use for #default_value? I've tried things like
'#default_value' => array(1 => 'Name 1') '#default_value' => 1 '#default_value' => 'Name 1'
but I can't get any of them to work. Any ideas?
Thanks.
Steve
Greg Holsclaw wrote:
Make the #default_value an array of the keys of the options
you want
selected.
$form['item'] = array( '#type' => 'select', ... '#options' => array of all options, '#default_value' => array of keys from above options. ... );
Check
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html%3E /5#default_value for more info.
Greg
-----Original Message----- From: support-bounces@drupal.org [mailto:support-
bounces@drupal.org] On
Behalf Of Steve Edwards Sent: Tuesday, November 27, 2007 8:25 PM To: support@drupal.org Subject: [support] How to add "selected" attribute to select list
<option>tag
Well, I'm back again, and this time I have a question about
attributes> for select options in a form. I have a form that has a
select element (multi-select) that lists users. The form
is for some
admin settings for a module. When the form is displayed,
I
need to be able to highlight specific options in the list
based on data
returned from a query. I've been looking all day, and haven't been able to figure it out. There is the
#attribute key, but it
is for the field as whole (at least as far as I can determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would
appreciate it.
Thanks.
Steve
-- [ Drupal support list | http://lists.drupal.org/ ]
Research Computing Services Sarah.Vardy@student.griffith.edu.au 0402241794
hey steve,
try the cck form markup module.
you can use cck for loads of stuff.
cheers,
sarah
----- Original Message ----- From: Steve Edwards killshot91@comcast.net Date: Wednesday, November 28, 2007 2:25 pm Subject: [support] How to add "selected" attribute to select list <option> tag To: support@drupal.org
Well, I'm back again, and this time I have a question about attributes for select options in a form. I have a form that has a select element (multi-select) that lists users. The form is for some admin settings for a module. When the form is displayed, I need to be able to highlight specific options in the list based on data returned from a query. I've been looking all day, and haven't been able to figure it out. There is the #attribute key, but it is for the field as whole (at least as far as I can determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would appreciate it.
Thanks.
Steve
[ Drupal support list | http://lists.drupal.org/ ]
Research Computing Services Sarah.Vardy@student.griffith.edu.au 0402241794
also try Ajax Form Builder I haven't used it but it does let you make customised forms...
----- Original Message ----- From: Sarah.Vardy@student.griffith.edu.au Date: Wednesday, November 28, 2007 2:46 pm Subject: Re: [support] How to add "selected" attribute to select list <option> tag To: support@drupal.org
hey steve,
try the cck form markup module.
you can use cck for loads of stuff.
cheers,
sarah
----- Original Message ----- From: Steve Edwards killshot91@comcast.net Date: Wednesday, November 28, 2007 2:25 pm Subject: [support] How to add "selected" attribute to select list <option> tag To: support@drupal.org
Well, I'm back again, and this time I have a question about attributes for select options in a form. I have a form that has a select element (multi-select) that lists users. The form is for some admin settings for a module. When the form
is
displayed, I need to be able to highlight specific options in the list
based
on data returned from a query. I've been looking all
day,
and haven't been able to figure it out. There is the #attribute key, but it is for the field as whole (at least as far as I can determine), and doesn't work for each individual <option> tag.
If anybody could point me in the right direction, I would appreciate it.
Thanks.
Steve
[ Drupal support list | http://lists.drupal.org/ ]
Research Computing Services Sarah.Vardy@student.griffith.edu.au 0402241794
Research Computing Services Sarah.Vardy@student.griffith.edu.au 0402241794