开发者

Programmatically creating forms - default selected index of a select

开发者 https://www.devze.com 2022-12-19 14:28 出处:网络
Part of a form I\'ve created in Drupal 6 is: $form[\'limiter\'] = array( \'#type\' => \'select\', \'#id\' => \'limiter\',

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

  $form['limiter'] = array(
        '#type' => 'select',
        '#id' => 'limiter',
        '#options' => array('10'=>'1开发者_高级运维0','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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消