tags:

views:

65

answers:

1

Hi,

Part of a form I've created in Drupal 6 is:

  $form['limiter'] = array(
        '#type' => 'select',
        '#id' => 'limiter',
        '#options' => array('10'=>'10','25'=>'25','50'=>'50')
      ); 

Which works fine.

However how do I define the default selected index so '25' is selected when the page loads? Anything I pass to '#default_value' doesn't seem to work.

Any advice appreciated!

+2  A: 

It's through #default_value - if that's not working, there's some other problem with your code external to the snippet you attached. Note that #default_value will only work on the first load of the page; afterwards the value selected by the user will override it.

$form['limiter'] = array (
    '#type' => 'select',
    '#id' => 'limiter',
    '#options' => array('10'=>'10','25'=>'25','50'=>'50'),
    '#default_value' => '25'
);

See http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#default_value

meagar
Yes, this is the answer and works. Make sure you are including a comma at the end of the '#options' line
Mike Munroe