0

Hello all of you super helpful people. :)

Drupal 8

Webform: Version: 8.x-5.19

I have created a webform which requires the person completing the form to select one of 4 options and whatever they select determines what fields they see or not.

One of the fields, when selected, needs to take the person to a different URL upon submission, but I am having a difficult time finding out if this is even possible to do...

EXAMPLE

Select:

  • Home (submit button takes you to the confirmation page)
  • Work (submit button takes you to the confirmation page)
  • Campaign (submit button would take you to a different URL (internal or external)

Does this make sense? Is this even possible to do?

Any assistance with this would be greatly appreciated!

Thank you!

1 Answer 1

3

As there is nothing out of the box that will support this the good news it is quite straight forward in a custom module.

in this example i have admin/structure/webform/manage/WEBFORMID/settings/confirmation

Confirmation type: -> Page (redirects to new page and displays the confirmation message) aka normal in your case for "Home" and "Work"

then you need a custom module to do ...

/**
 * Implements hook_form_alter().
 */
function MYODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // You will need your $form_id.
  // dump($form_id);
  if ($form_id == 'webform_submission_test1_add_form') {
    $form['actions']['submit']['#submit'][] = 'MYODULE_test_form_submit';
  }
}
/**
 * Implements hook_form_submit(). ish.
 */
function MYODULE_test_form_submit(&$form, FormStateInterface $form_state) {
  $form_values = $form_state->getValues();
  // this needs to be your element key.
  if (!empty($form_values['select_one'])) {
    if ($form_values['select_one'] === 'campaign') {
      // Redirect to some page
      $form_state->setRedirect('entity.node.canonical', [
        'node' => 7
      ]);
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.