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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题