I want to add a custom validation handler to the exposed filter form that is part of a view.
I am not able to target that specific exposed filter form: The validation handler is added to other forms too.

Is there a way to add a validation handler only to a specific exposed filter form and avoid the validation handler is added to other forms too, including other forms for exposed filters?

1 Answer 1


To form alter a specific view exposed filter form, you need 2 conditions to check: the form id & the form's '#id' element.

function MYMODULE_form_alter(&$form, $form_state, $form_id) {

  // @NOTE: $form['#id'] will vary based on your your view & display machine names.
  // Here the view machine name is 'view' & display machine name is 'display'.
  // Use Devel's dpm() to inspect or the Views administration UI
  // to find your own form's values.

  if ($form_id == 'views_exposed_form') {
    if ($form['#id'] == 'views-exposed-form-view-display') {
      // @TODO: Add form alter code.


Your Answer

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