Skip to main content
1 of 4
Cool
  • 1.8k
  • 2
  • 23
  • 44

Identify submit button in webform in Drupal 8

I am trying to add additional submit buttons to the webform to navigate between different steps. I have added button like below:

function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if($form_id == 'mywebform_id') {
    $form['actions']['submit_button_step_1'] = array(
      '#type' => 'submit',
      '#value' => t('Go to Step 1'),
      '#submit' => array('custom_navigation'),
    );
    $form['actions']['submit_button_step_2'] = array(
      '#type' => 'submit',
      '#value' => t('Go to Step 2'),
      '#submit' => array('custom_navigation'),
    );
}
}
function custom_navigation(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $value = $form_state->getValues();
  //echo '<pre>';print_r($form['actions']);echo '</pre>';exit;
}

But, I'm using same custom submit handler both the custom buttons. How I identify which button has clicked by user?

Cool
  • 1.8k
  • 2
  • 23
  • 44