doukuanghuan7582 2010-07-20 10:34
浏览 24
已采纳

单击“提交”或“预览”后未调用hook_form_FORM_ID_alter

In a custom module, I have the following (to add javascript to a particular form):

function mymodule_form_mynode_node_form_alter(&$form, $form_state) {
  drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodule.js', 'module');
}

This function does get called the form is first loaded (i.e. browse to http://myserver.com/node/add/mynode) however this php function does not get called when the same form is reloaded after the form has been invalidated (i.e. missed a required field after clicking 'Submit' or 'Preview').

What do I need to do to have the javascript file added after 'Submit' or 'Preview' is clicked?

Thanks,

John

  • 写回答

2条回答 默认 最新

  • douqiang7976 2010-07-25 12:23
    关注

    You form alter is only called when the form is build. As forms are cached between request, the same and already build form is used on submit and preview.

    You need to unsure that your code is called each time the form is rendered. As pointed out by googletorp, one way to do it is to use a custom form rendering function. You can also do it by attaching a post or pre-rendering function to your form. Actually, the custom, pre or post rendering function doesn't need to be for the form itself and can be used on any form element. Preferably the one which behavior is altered by the JavaScript.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。