2010-09-02 76 views
1

如何指定默認值並隱藏此複選框?我可以修剪圖像嗎?

[states] => Array 
     (
      [#type] => checkboxes 
      [#title] => Status 
      [#options] => Array 
       (
        [active] => Active users 
        [inactive] => Inactive users 
       ) 

      [#description] => Subscriptions matching the selected states will be exported. 
      [#required] => 1 
     ) 

我已經試過

$form['states']['#default_value'] = 'active'; 

,但它給我一個錯誤.. 感謝

+0

爲什麼你不發佈錯誤,所以我們不必猜測出什麼問題。 – googletorp 2010-09-02 20:42:21

回答

0

您的代碼書面會產生一個語法錯誤,因爲你聲明「狀態'陣列錯誤。這是一種PHP語法,與Drupal的表單API沒有任何關係。

嘗試:

$form['states'] => Array (
    '#type' => 'checkboxes', 
    '#title' => t('Status'), 
    '#options' => Array (
    'active' => 'Active users', 
    'inactive' => 'Inactive users', 
    ), 
    '#description' => t('Subscriptions matching the selected states will be exported.'), 
    '#required' => 1, 
    '#default_value' => 'active', 
); 

無關的語法問題,一個更好的方式做這將是整個窗體元素重置爲「#TYPE」 =「值」。例如$form['states']['#type'] = 'value'; $form['states']['value'] = 'whatever'