The error means that form_token
needs is invalid and needs to be regenerated. This is basically a hidden form field (generally used to protect against cross-site forgeries).
Normally a token element is automatically added to each Drupal form by drupal_prepare_form()
, so you don't generally have to add one yourself, unless you're writing your own code.
If you're trying to program some multi-page form, you probably need to re-generate the token on each submit using drupal_get_token()
, e.g. as shown here:
$form_state['input']['form_token'] = drupal_get_token($form['#token']);
As for workaround to force regeneration of form token in form_alter, check the following example:
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id === 'your_form_entityform_edit_form' && !empty($form_state['input']['form_id'])) {
$form_id = $form_state['input']['form_id'];
$form ['#token'] = $form_id;
$form ['form_token'] = array(
'#id' => drupal_html_id('edit-' . $form_id . '-form-token'),
'#type' => 'token',
'#default_value' => drupal_get_token($form['#token']),
'#parents' => array('form_token'),
);
}
}
Troubleshooting
Double check if your form is not hardcoded, otherwise add the token as suggested by @thirdender:
<input name='form_token' type='hidden' value='<?php print drupal_get_token('MY_FORM_ID'); ?>'>
Check if the error happens on your form, as it could on other form (e.g. form within the form).
- Debug
drupal_valid_token()
.
<input name='form_token' type='hidden' value='<?php print drupal_get_token('MY_FORM_ID'); ?>'>
the form was able to submit properly.