I am trying to redirect users to the anchor of the error form field after form validation.
In the form I set the form validation handler with the following code.
$form['#validate'] = 'my_form_validate';
In the validation handler, if the form shows some error message, I am trying to scroll to error field.
function my_form_validate() {
...
$form_state['redirect'] = 'node/' . $form['nid']['#value'] . '#' . $error_field_anchor;
...
}
The form is not redirecting after validation.
I have tried other paths, such as user/1, node/123 without anchor but the form is not getting redirected to that one.
drupal_goto($path);
$form['#validate'] = 'my_form_validate'
replaces any existing validation handler, which may explain why the redirect isn't happening: No validation error is set. This is probably a task to do with JavaScript as what you want to achieve is scrolling the page. Unfortunately, we cannot say why the redirection doesn't take place, since we don't know the code that checks when users should be redirected (which could be wrong code) nor in which hook is the form validation handler added (which could target the wrong form or not form at all).