0

I've searched and cant find an answer to this specific question.

If I have a view and an exposed filter for that view in a block, when the user clicks submit on the exposed filter form, how can I get the values of the exposed filters in order to use the value elsewhere for a different purpose? For example saving the value of one of the exposed filters into private temp store for use later.

What hook can i use that is called when the user clicks submit on the exposed filter form? The only information I can find is regarding hooks that are called when the view is being built.

Or am i approcahing this wrong and should I be looking into the form submit function for the exposed filters form?

1 Answer 1

3

You want to add a submit handler to your exposed form

function HOOK_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

    array_unshift($form['#submit'], '_my_exposed_form_submit');
}

function _my_exposed_form_submit(&$form, 
   \Drupal\Core\Form\FormStateInterface $form_state) {

   $values = $form_state->getValues();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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