1

I have an interesting question. There is a custom module that defines form -> form validate and form submit

I am not allowed to touch this module, still I want to execute another custom action on submit (OR validate).

I have added $form['#validate'][]='_custom_validator'; in my hook_form_alter So the $form array has two functions that validate. And that seems to work, the problem is I have to "copy-paste" the validation code from the other module (the code inside hook_form_validate).(To prevent any incorrect form validation). This is considered as a bad design pattern.

Question: Is there somewhere a property that defines the order of the validations ?

Cheers

  • The validation & submit handlers are called in the same order they're defined in the #validate and #submit properties. Chris Rockwell's answer is correct, and will run your validation first, and the module's own validation after. – Yuriy Babenko Jul 19 '13 at 17:28
4

You can use array_unshift to make sure your validation is called first:

array_unshift($form['#validate'], '_custom_validator');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.