Skip to main content
Tweeted twitter.com/#!/StackDrupal/status/59091031878152193
added 55 characters in body; edited title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How can I add an extra button & submit handler to an expoised viewsexposed 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(&$form, &$form_state, $form_id) { switch ($form_id) { case 'views_exposed_form':

function my_module_form_alter(&$form, &$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, &$form_state) {
  // do something here
}

}

function my_module_button_handler($form, &$form_state) { // do something here }

How can I add an extra button & submit handler to an expoised views 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(&$form, &$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, &$form_state) { // do something here }

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(&$form, &$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, &$form_state) {
  // do something here
}
Source Link
chipcleary
  • 593
  • 5
  • 13

How can I add an extra button & submit handler to an expoised views 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(&$form, &$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, &$form_state) { // do something here }