情况
我正在使用 Drupal Form API 实现一些表单。作为用户选择的结果,我需要显示可视化(面积图、时间线等),其中我必须加载 google 的 JS 库并发送数据以在 div 元素中显示视觉效果。
我所做的:
我尝试在表单的提交处理函数中使用 drupal_add_js 加载本地 JavaScript 文件(这又加载 Google VIZ api),并使用 echo 添加了一些 HTML 代码< DIV>元素。
问题:
显然这不起作用。请提出解决方案或任何替代方法。我想做的就是使用 form_redirect 到另一个节点,其中我拥有所有 HTML 和 JavaScript 代码,但我希望结果出现在同一 URL 上。如果您需要更多详细信息或任何说明,请发表评论。
感谢您的耐心等待。
The situation
I am implementing a few forms using the Drupal Form API. As a result of user selection i need to display a visualization (area chart, time line, etc) where i have to load the google's JS libraries and send data to display the visual in a div element.
What I have Done:
I have tried to load a local JavaScript file(this in turn loads Google VIZ api) using drupal_add_js in the submit handler functions of the form and i added some HTML code using echo for the < DIV> element.
The problem:
Apparently this does not work. Please suggest a solution or any alternate methods. The one i have thought of doing is to use form_redirect to another node where i have all the HTML and JavaScript Code, but i would like the results to appear on the same URL. If you need further details or any clarification please comment.
Thank you for your patience.
发布评论
评论(1)
要将 html 标记添加到 drupal 表单,您可以使用 '#type' = 'markup':
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/#markup
(事实上,您可以将其省略,因为它是表单元素的默认类型。)
不过,在提交函数中添加 javascript 听起来太晚了。尝试将其添加到表单中(也许通过 hook_form_alter()),并在填写适当的字段时触发它。
To add html markup to a drupal form, you can use '#type' = 'markup':
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/#markup
(in fact, you can leave it out as it's the default type for form elements.)
Adding the javascript in the submit function sounds too late, though. Try adding it to the form (through hook_form_alter(), perhaps) and triggering it when the appropriate field is filled out.