我想在现有表单中添加新项目。我有表格的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;
}
}
答案 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';