简体   繁体   English

Drupal中的hook_form_FORM_ID_alter函数

[英]hook_form_FORM_ID_alter function in Drupal

I would like to overwrite a form by creating a custom module. 我想通过创建自定义模块来覆盖表单。 But therefor, I need to get a hold to my form ID in the function. 但是为此,我需要保留该函数中的表单ID。

Drupal.org mentionned the hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) function, but when I apply this to my form, it doesn't respond. Drupal.org提到了hook_form_FORM_ID_alter(&$form, &$form_state, $form_id)函数,但是当我将其应用于表单时,它没有响应。 Do I have a syntax error when I use following statement?: 使用以下语句时是否出现语法错误?:

function redactie_omgeving_fiche_node_form__form_alter(&$form, $form_state, $form_id) {
    echo(var_dump('ONZE redactie_omgeving__fiche_node_form__form_alter'));
}

and this is my form: 这是我的表格:

<form class="node-form node-fiche-form" enctype="multipart/form-data" action="/node/1/edit" method="post" id="fiche-node-form" accept-charset="UTF-8">

A nice little trick to make sure you have the right form id is to first use hook_form_alter() to get the form id, then use hook_form_FORM_ID_alter() . 确保您具有正确的表单ID的一个不错的小技巧是,首先使用hook_form_alter()获取表单ID, 然后使用hook_form_FORM_ID_alter() For example, use: 例如,使用:

function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
  drupal_set_message($form_id);
}

to see a Drupal message of all form id's on the current page. 在当前页面上查看所有表单ID的Drupal消息。 Once you have the correct id, then place it into hook_form_FORM_ID_alter() . 拥有正确的ID后,将其放入hook_form_FORM_ID_alter() Try that and make sure you are using the right form id. 尝试这样做,确保使用正确的表单ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM