像往常一样,我认为 Drupal 表单 API 中的某些内容会很简单......我在想什么?
问题
我有一个通过 drupal_get_form() 输出表单的块。不知何故,在块的显示函数中,我想检查表单是否未通过验证(即,在表单的验证函数中存在由 form_set_error() 设置的任何错误)。
到目前为止尝试过...
- 后它们就消失了
- 在块显示功能中检查
$_SESSION['messages']['error']
- 但检查$_POST 没有任何用处
- 块显示函数中的 - 这里检查
mymodule_preprocess_page()
中的 form_get_errors()
- - 空检查
form_get_errors()
中mytheme_preprocess_page()
- 空
我对 form_get_errors() 为空。它调用 form_set_error() ,不带参数- 留下$reset = FALSE
,因此保存表单错误的静态变量不会被清除。所以我不知道那个 var 在哪里被重置——另一个表单 api 函数在哪里? - 这样当我在模块或主题中调用它时,它是空的。
帮忙?
那么,有谁知道在清除静态变量之前什么时候(预处理函数?)我可以调用 form_get_errors()
?或者有另一个想法如何检查显示表单的块中的表单错误? (顺便说一句 - 我相当确定一旦我进入 drupal_get_form()
调用的函数,我就可以轻松检查这一点......但我需要了解封闭块显示函数中的错误。 )
As usual, I thought something in the Drupal forms API would be simple... what was I thinking?
Problem
I have a block that outputs a form via drupal_get_form(). Somehow in the block's display function, I want to check whether the form failed validation (i.e. has any errors that were set by form_set_error() in my form's validation function).
Tried so far...
- checking
$_SESSION['messages']['error']
in block display function - but they are gone by then
- checking
$_POST
in block display function - nothing useful here
- checking
form_get_errors()
in mymodule_preprocess_page()
- empty
- checking
form_get_errors()
in mytheme_preprocess_page()
- empty
I am confused by my calls to form_get_errors() being empty. It calls form_set_error() with no args - which leaves $reset = FALSE
, thus the static var that holds the form errors does not get cleared. So I don't know where that var is getting reset - somewhere by another forms api function? - so that by the time I call it in my module or theme, it's empty.
help?
So, does anyone know at what point (preprocess functions?) I can call form_get_errors()
before the static var is cleared? Or have another idea how to check for form errors in the block that displays the form? (By the way - I am fairly sure I could check this easily once I am inside my function that drupal_get_form()
calls... but I need to know about the errors in the enclosing block display function.)
发布评论
评论(1)
这很丑陋,因为所有人都出去了,但它应该有效。
This is ugly as all get out but it should work.