Drupal 6表单Api将项目添加到现有表单

时间:2010-09-08 13:13:20

标签: drupal drupal-6 drupal-modules drupal-fapi

我想在现有表单中添加新项目。我有表格的ID,我知道我需要使用hook form_alter但不知道如何添加它。

function modulename_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
        case 'form id goes here':
            // Need to do something here....         
        break;
    }
}

1 个答案:

答案 0 :(得分:1)

因为&$form变量是一个引用,所以无论你做什么都会改变原始值。所以只需将其添加到$form;

//After, need to do something here:
$form['my_new_field'] = array(

 '#type' => 'select',
 //etc..

 );


//You can also add a new validation here:

$form['#validate'][]  = 'my_valiation_callback';

请参阅drupal api ref for better details: