How can I add an extra button & submit handler to an exposed view form? I would like to add a second button to an exposed view form.

I am able to get the button to display, but not to have it call the button submit handler. Instead, it behaves just like the standard search button that views provides automatically.

How can I have my second button call a separate handler?

Below is what I've tried to do. 

(FWIW, my specific goal is to let the user use the exposed view form to search for an existing node, then if he doesn't find it, to go ahead and post a new node. So, I want a button that will call an action to post a new node.)



function my_module_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  switch ($form_id) {
    case 'views_exposed_form':
      if ($form['#id'] = 'views-exposed-form-my-module-page-1') {
        // Add a button
        $form['my_button']['#type'] = 'button';
        $form['my_button']['#value'] = t('My Extra Button');
        $form['my_button']['#submit'] = array('my_module_button_handler');
      }
      break;
  }
}

function my_module_button_handler($form, &amp;$form_state) {
  // do something here
}
The submit handler is not called by default on a form api element type "button". If you want to execute a submit handler on a button you will need to add

$form['my_button']['#executes_submit_callback'] = TRUE;


As a side note this will not be the case if the #type was 'submit' because the executes_submit_callback is by default equal to true on that element type.

Hope this helps.