开发者

Double output within Drupal function

开发者 https://www.devze.com 2023-02-01 18:09 出处:网络
I\'m goin开发者_开发知识库g crazy function module_form_alter(&$form, $form_state, $form_id) { // Nothing here

I'm goin开发者_开发知识库g crazy

function module_form_alter(&$form, $form_state, $form_id) {

// Nothing here

$var = 'bla-bla';
print_r($var);

// Nothing here

}

I see on the screen bla-blabla-bla

WHY?


You probably have two forms on the page. Try printing (better yet, install devel and use dpm) $form_id instead of $var and see which forms are involved.


hook_form_alter works on every form. You probably have the search form in this page, so it prints the text twice (one for every form).

In order to add changes to only one form, use the $form_id argument like this:

function module_form_alter(&$form, $form_state, $form_id) {

  if($form_id == 'YOURFORMID') {
    $var = 'bla-bla';
    print_r($var);
  }
}

change YOURFORMID to your form_id.

You can find the form_id by looking on the HTML of the form output and search the value of the input that his name is 'form_id'.

0

精彩评论

暂无评论...
验证码 换一张
取 消