如果您查看 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;
}
}`
这表明此处设置了“表单已过时”消息。因此,您可以通过取消设置来使isset($form[#token'])
条件为假,#token
以防止出现此消息。
您所要做的就是加载您要验证的表单状态,并在调用
unset($form[#token']);
之前调用drupal_validate_form
。