我正在尝试将表单状态保存在数据库中,并希望在列表页面中查看其错误验证。
即,我想验证数据库中以前保存的表单状态。
这是一个节点类型表单。
我已经尝试过node_validate
它不起作用,因为我在提交节点之前获取了数据。所以没有 nid 并且它不起作用
还尝试了drupal_validate_form
,但它显示了
[form_token] => The form has become outdated. Copy any unsaved work in the form below and then reload this page
编辑
任何有帮助的人,“如何将表单输入保存在数据库中并从数据库中检索它而不提交表单。
提前谢谢
任何帮助都是非常值得赞赏的。
最佳答案
如果您查看 Drupal Core,您会在 includes/form.inc
的 drupal_validate_form
函数中看到这一点:
if (isset($form['#token'])) {
if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) {
$path = current_path();
$query = drupal_get_query_parameters();
$url = url($path, array('query' => $query));
// Setting this error will cause the form to fail validation.
form_set_error('form_token', t('The form has become outdated. Copy any unsaved work in the form below and then <a href="@link">reload this page</a>.', array('@link' => $url)));
// Stop here and don't run any further validation handlers, because they
// could invoke non-safe operations which opens the door for CSRF
// vulnerabilities.
$validated_forms[$form_id] = TRUE;
return;
}
}`
这表明此处设置了“表单已过时”消息。因此,您可以通过取消设置 #token
使 isset($form[#token'])
条件为 false,以防止出现此消息。
您所要做的就是加载要验证的表单状态,然后调用
在调用 drupal_validate_form
之前 unset($form[#token']);
。
关于drupal - 如何显示/验证节点列表页面的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25659607/