views:

22

answers:

1

I know this is somewhat of a newb question but I am running into a deadline and 3 days of Drupal experience will just not cut it...

$form['gender'] = array('#type' => 'select', '#title' => t('Gender: *'), '#options' => array(t('Male'), t('Female')), '#required' => TRUE, '#weight' => 2, );

How do I assign values to select values ? For example Male -> 'm' and Female-> 'f'. Also how do I give the select box a default caption "please select gender..."

Thanks guys

+3  A: 

Try this:

$options = array(
  '', => 'Please select a gender.',
  'm' => 'Male',
  'f' => 'Female',
);

$form['gender']['#options'] = $options;

In your validation function (after the form submits) you should make sure the user picks a value that isn't "".

Kevin

related questions