Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The module contains an important check for form errors, BUT this will never work because hook_form_alter is not called in such cases. See: https://www.drupal.org/node/671574
I had to debug a lot until I found that out...
I ended up this way...
/**
* Implements hook_form_alter().
*
* Just add javascript to all forms.
*
* @param $form_id
* name of the form being acted on
* @param $form
* array with form structure
*/
function saveguard_form_alter(&$form, &$form_state, $form_id) {
$form['#after_build'][] = 'saveguard_form_alter_after_build';
}
/**
* After build callback to run even if the form contains errors!
*/
function saveguard_form_alter_after_build($form, &$form_state) {
$form['field']['#prefix'] = 'This text will rule them all!';
drupal_add_js(drupal_get_path('module', 'saveguard') . '/saveguard.js');
static $done;
if (!$done) {
$settings['saveguard'] = array(
'msg' => variable_get('saveguard_message', NULL),
);
drupal_add_js($settings, array('type' => 'setting', 'scope' => 'header', 'group' => JS_DEFAULT));
$done = TRUE;
}
return $form;
}
An that finally works :) :)
Comments
Comment #2
AnybodyError functionality is broken completely so I'll correct the priority.
Comment #3
geek-merlinYes right. We should do something like this in hook_form_alter: