Score:0

How can i programmatically get the value of a views exposed filter after the user submits the form?

cn flag

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?

Score:1
kr flag

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();
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.