Last updated 5 September 2015. Created on 16 May 2011.
Edited by sassafrass, danielb. Log in to edit this page.

The Select (or other) module provides a Forms API element, and integrates it with the Fields API. However, developers and coders can make use of this element in a custom form for any purpose. This page outlines the developer usage and available attributes.

Example developer usage in Forms API

$form['my_field'] = array(
  '#type' => 'select_or_other',
  '#title' => t('Choose an option'),
  '#default_value' => array('value_1'),
  '#options' => array(
    'value_1' => t('One'),
    'value_2' => t('Two'),
    'value_3' => t('Three'),
  '#other' => t('Other (please type a value)'),   // Text to show as 'other' option
  '#required' => TRUE,
  '#multiple' => TRUE,
  '#other_unknown_defaults' => 'other', // If the #default_value is not a valid choice in #options, what should we do? Possible values 'append', 'ignore', 'other'  (if 'other' specified you can also override #other_delimiter).
  '#other_delimiter' => ', ', // Delimiter string to delimit multiple 'other' values into the 'other' textfield.  If this is FALSE only the last value will be used.
  '#select_type' => 'select', // Defaults to 'select'.  Can also be 'radios' or 'checkboxes'.

The #properties you give the element that are recognised as FAPI select properties will be automatically assigned to the Select element. Also any #properties assigned as #select_property or #other_property will be passed down to the corresponding form element. For example, to use ajax with the select_or_other element, use the property #select_ajax or #other_ajax, instead of simply #ajax.

Looking for support? Visit the forums, or join #drupal-support in IRC.


gregoryshearer’s picture

I did not see this mentioned anywhere but this is a little bit of CSS that will insert a line of text before/above the other text field when it appears.

#edit-submitted-stateprovincecode-other-wrapper:before {
content: "Please enter the State that is not on the list.";

Of course you need to change the field name to whatever you are using.

carl.brown’s picture

The CSS :before selector is unsupported in IE7 and below, with only partial support in IE8. So use this with caution. It would be better to use a hook to add this content in instead.

danielb’s picture

The way I do it is to use either #other_prefix or #other_field_prefix. Simple.

airspoon’s picture

I'm some-what new to Drupal and am familiar with PHP, but just barely. With that being said, can I cut and past the above code into the "allowed values PHP code" on the "field settings" page for it to work? Is that how I can get this module to work, or is it something else?


danielb’s picture

No. This documentation is for module developers. If using with fields use the 'text' or numeric field types and choose Select (or other) to be the widget.

oranges13’s picture

Very informative. Thank you for thinking of developers :)

mortona2k’s picture

If other is selected along with another option, is this counted as valid, invalid, or is it configurable? I need a multiple checkbox widget that allows me to collect at least one selection, including other. The ability to write in that other is icing on the cake. Does this module work for me?

The other Andrew Morton

danielb’s picture

Yes it should. Think of the whole thing like a textfield where anything goes, except there are a few easy select options to help users out or nudge them in the right direction.

laura s’s picture

I assume the "other" value does not end up adding the entry to the vocabulary as a new term, but it might be worth clarifying how "other" value is handled.

_____ ____ ___ __ _ _
Laura Scott :: design » blog » tweet

ptmkenny’s picture

On the field edit page, the "Other value as default value" allows you to select how other will be handled:

  • Add the values to the other textfield-> store the value but don't change the list
  • Append the values to the current list-> store the value and add to the list attached to the node/user/entity
  • Append the values to the available options-> store the value and add the value to the list so that it can be selected on other nodes/users/entities
  • Ignore the values-> do not store the value
ThaRaven403’s picture


I'm currently using this element as a select dropdown. Options are filled with a key/value array, with the key being the ID of the list items (which I'll use to submit). But when something is entered in the "other" field instead, I'll be submitting through another method to send the entered text.

So my question is, is there was a way to identify if a value was selected or if something was entered in the "other" field? I could check that if the value is a long then it is an ID, otherwise it's not, but then again someone could enter numbers in the "other" field, and I don't think anyways that it's the best method to verify this...

Thanks in advance,

adaddinsane’s picture

#other_element_validate => array('my_other_element_validation'),

Steve Turnbull
Like SF/F? Read

bkirkendall’s picture

I just installed the Select or Other module on my site and implemented it in a custom module of my own. However, the form where I use it depends on the use of #ajax to dynamically trigger changes to other fields based on the values supplied for the select or other field. If #ajax is not supported directly, is there a suggested work-around? Many thanks!

ericbellot’s picture

In Drupal 8 version, the module Select Or Other provide 2 FAPI elements:

  • select_or_other_select: display a selection list
  • select_or_other_buttons: display radios buttons or checkboxes depending of required parameter.

Other settings seem not be changed.

dafeder’s picture

If you are updating a field defined as select_or_other via Services' REST API, this module will lead to a slightly unexpected schema for field update. To switch select values, for instance, you would need a PUT request to do something like

curl -X PUT -i -H "Content-type: application/json" -d '{
  "field_some_select_or_other_field": {"und": {"select": {"value": "your_key"}}}
subhra44’s picture

It seems if you select Other from the select dropdown, the other text field is mandatory. How make the field non mandatory without modifying the validate function in module?

bdone’s picture

if you need to implement the select_or_other_taxonomy module, included as of 7.x-3.0-alpha2, add the non-forms API property named "#field_widget", as shown in this example:

  $form['my_term_reference_field'] = array(
    '#type' => 'select_or_other',
    '#title' => t('Select your terms.'),
    '#required' => TRUE,
    '#multiple' => TRUE,
    '#select_type' => 'checkboxes',
    '#field_widget' => 'select_or_other_taxonomy',
    '#other_unknown_defaults' => 'other',
    '#other_delimiter' => FALSE,
    '#options' => i18n_taxonomy_allowed_values(field_info_field('your_term_field_machine_name_here')),