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

user363036
  • 319
  • 1
  • 2
  • 7

1 Answers1

3

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
  • 13,153
  • 11
  • 60
  • 87