2010-09-19 134 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 
    } 
} 

在您做了必要的修改之后,您可以简单地提交到创建表单的默认提交操作。