Drupal 模块开发:如何在 form_submit 和页面处理函数之间进行通信
我正在编写一个模块,我需要从页面处理函数中检索 form_submit 函数中设置的值。原因是我在与页面处理程序相同的页面上呈现表单提交的结果。
我有这个工作,但我使用的是全局变量,我不喜欢它。我希望能够为此使用 $form_state['storage'] ,但不能,因为我无法从页面处理程序访问 $form_state 变量。
有什么建议吗?
I am writing a module and I need to retrieve values set in a form_submit function from a page handler function. The reason is that I am rendering results of a form submit on the same page as the page handler.
I have this working, but I am using global variables, which I don't like. I'd like to be able to use the $form_state['storage'] for this, but can't since I don't have access to the $form_state variable from the page handler.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回复: Drupal:如何在与表单相同的页面上呈现表单结果
您无权访问页面处理程序中的 $form_state,但我认为您的表单构建器功能可能会自动使用它。看看是否可以使用类似的方法将其转储出来。
另一种可能性(虽然并不比使用全局变量好多少)是使用Drupal的variable_set()和variable_get函数。
如果您只处理单个值,您可以将其作为 URL 参数从提交处理程序中的 $form['#redirect'] 传递到页面。
RE: Drupal: How to Render Results of Form on Same Page as Form
You don't have access to $form_state in the page handler, but I think it might be available to your form builder function automatically. See if you can dump it out using something like
Another possibility, though not much better than using globals, would be to use Drupal's variable_set() and variable_get functions.
If you're dealing with just a single value you could pass it to page as a URL argument from a $form['#redirect'] in the submit handler.