Select (or other)

danielb - February 27, 2009 - 03:38

Provides a new Forms API element which is a select/radios/checkboxes element that has an 'other' option. When 'other' is selected a textfield appears for the user to provide a custom value.

This is for developers to use in form functions, there is no CCK/Profile etc... integration.

See this issue for a Webform integration patch.

Example usage:

<?php
$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.

Releases

Official releasesDateSizeLinksStatus
6.x-1.42009-Oct-038.77 KBRecommended for 6.xThis is currently the recommended release for 6.x.
Development snapshotsDateSizeLinksStatus
6.x-1.x-dev2009-Oct-249.82 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.


 
 

Drupal is a registered trademark of Dries Buytaert.