Skip to main content
Tweeted twitter.com/StackDrupal/status/1062042417396879361
Fixed code snippet indentation, enhanced readability
Source Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

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? And based on user click I need to redirect user to corresponding wizard page.

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? And based on user click I need to redirect user to corresponding wizard page.

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? And based on user click I need to redirect user to corresponding wizard page.

edited title
Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

Identify submit button in webform in Drupal 8

added 78 characters in body
Source Link
Cool
  • 1.8k
  • 2
  • 23
  • 44

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? And based on user click I need to redirect user to corresponding wizard page.

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?

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? And based on user click I need to redirect user to corresponding wizard page.

Source Link
Cool
  • 1.8k
  • 2
  • 23
  • 44
Loading