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

发布于 2024-09-18 23:49:21 字数 295 浏览 2 评论 0原文

我想将新项目添加到现有表单中。我有表单的 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;
    }
}

I want to add a new item into an existing form. I have the ID of the form and I know I need to use hook form_alter but not sure how to add it.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀念你的温柔 2024-09-25 23:49:23

因为 &$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欲了解更多详细信息:

Because the &$form variable is a reference, whatever you do to it changes the original value. so just add it to $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';

See the drupal api ref for better details:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文