Drupal form not validating

In the object oriented way, we need to have a class and a static method that will be called on validate/submit. * * @param array $form * @param \Drupal\Core\Form\Form State Interface $form_state */ public static function example_form_validate(&$form, Form State Interface $form_state) /** * Submit the example_form.

There is an optional form element called $form['#after_build'] it takes an array of functions to call (similar to $form['#submit']).

Placing the drupal_add_js or drupal_add_css into the after_build solves these issues.

Here is some basic code for reference, which goes into one of your custom modules.

Depending on the weight of the modules your form_alter may get overwritten so the solution is to run it after the form has been built.

At this point you want to make sure it runs the alterations in the contributed modules first before your change occurs, then it is best to use #after_build.

294

Leave a Reply