2

我正在尝试将表单状态保存在数据库中,并希望在列表页面中查看其错误验证。

即,我想从我的数据库中验证以前保存的表单状态。

这是一个节点类型的表格。

我已经尝试过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

编辑
任何有帮助的人,“如何在数据库中保存表单输入并从数据库中检索它而不提交表单。

先感谢您

任何帮助都是最可观的。

4

1 回答 1

2

如果您查看 Drupal Core,您会includes/form.incdrupal_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;
    }
  }`

这表明此处设置了“表单已过时”消息。因此,您可以通过取消设置来使isset($form[#token'])条件为假,#token以防止出现此消息。

您所要做的就是加载您要验证的表单状态,并在调用 unset($form[#token']);之前调用drupal_validate_form

于 2014-09-12T19:37:42.960 回答