0

I'd like to add a custom button near the "apply" button on a view exposed filter form. To do that I have created my own module and added a hook:

function mymodule_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    if ($form['#id'] == 'views-exposed-form-myview-page-1') {
        $form['actions'][] = array (
            '#type' => 'submit',
            '#value' => t('Custom redirect'),
            '#submit' => array('mymodule_secondary_submit_function'),
        );
    }    
}

function mymodule_secondary_submit_function() {
    return  new RedirectResponse('/my_new_target');
}

When clicking the button I want to redirect to another page. That's all I want. But when you click the button, It always applies filter, as if I had clicked "apply" button. I've tried changing 'submit' with 'button', using an '#ajax' callback, but without success.

  • Because I didn't find a way to do it, I have added a link (<a href..>) with a class and I set it look like a button through css. $form['actions'][] = array ( '#markup' => ...). – briast May 11 at 8:59

Your Answer

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

Browse other questions tagged or ask your own question.