I have added a custom form validation on node/add page in drupal 8. The purpose of adding this validator is to add a slash before the path alias string. By default if a path alias string is added without a slash then form validator gives an error asking to add a slash before string.

Now the problem is that the default validation is called before the custom validator.

The code have use is like :-

In my form_alter function

if (!is_array($form['#validate'])) {
  $form['#validate'] = array();
array_unshift($form['#validate'], 'my_custom_handler');

to add custom validator to the top of validate array.

Although, my custom validator is added to the top of validator array, still default validator is executing first.

Any help will be highly appreciated.

Thank you

  • Form element validation will always run first. Probably that could be your problem. On the otherhand could please elaborate more about the originalo issue? Standard Drupal installation shouldn't have this. Do you have any special contrib module, server settings, etc? – ssibal Sep 17 '18 at 14:42

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.