2010-09-19 136 views
0

我想添加自定義按鈕,Drupal的創建形式,因此如果用戶在點擊它,而不是提交按鈕,創建的對象變化的工作流狀態到另一個狀態(不是默認的第一狀態) 什麼建議嗎?如何添加按鈕到drupal表單?

回答

6

要修改,你必須一個form_alter鉤添加到您的模塊由Drupal的默認生成的形式。您可以通過定義一個函數來執行此操作,例如modulename_form_alter,假定您的模塊名稱爲modulename。 Drupal的體系通過了form陣列和陣列form_state你可以用它來覆蓋默認行爲。在你的情況下,完整的功能看起來像這樣。

function modulename_form_alter(&$form, $form_state, $form_id) { 
    if($form_id == 'what you want') { 
     $form['buttons']['another_button'] = array(
      '#type' => 'submit', 
      '#value' => 'Add to another state', 
      '#submit' => array('modulename_custom_form_submit') 
     ); 
    } 
} 

function modulename_custom_form_submit($form, &$form_state) { 
    if($form_state['values']['another_button'] == 'Add to another state') { 
     //Do your thing 
    } 
} 

在您做了必要的修改之後,您可以簡單地提交到創建表單的默認提交操作。