0

I want to show custom message on confirmation page (on custom URL). I created a custom URL in *.routing.yml file and added a method in controller class that returns an array :

return [
  '#theme' => 'mycustom_confirmation',
  '#test_var' => 'Test Value',
];

Next, in *.module file,

  1. I added hook_theme function to return below array:
    'mycustom_confirmation' => [     
          'variables' => ['mycustom_var' => NULL, 'webform' => NULL, 'source_entity' => NULL, 'webform_submission' => NULL],
        ]
  1. I added template_preprocess_mycustom_confirmation function to add my customized variables.

Then I created a template file: mycustom-confirmation.html.twig file where I consume the customized variables to show custom message.

After all that, when I landed to confirmation URL (that I set in to admin/structure/webform/manage/webinar_training_request_1/settings/confirmation page) after webform submission , I dont see any message. I dont understand what I missed in module.

1 Answer 1

1

This would be a nice starting point:

/erlendsays.module

<?php

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter().
 */
function erlendsays_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  array_unshift($form['actions']['submit']['#submit'], 'store_doublecheck_form_result');
}

function store_doublecheck_form_result(array $form, FormStateInterface $form_state) {
  Drupal::request()->getSession()->set("webform_result", $form_state->getValues());
}

/**
 * Implements hook_theme().
 */
function erlendsays_theme() {
  return [
    'doublecheck_form_result' => [
      'variables' => [
        'form_result' => NULL,
      ],
      'template' => 'doublecheck_form_result',
    ],
  ];
}

/erlendsays.routing.yml

erlendsays.doublecheck_form_result:
  path: '/doublecheckformresults'
  defaults:
    _controller: '\Drupal\erlendsays\Controller\DoublecheckFormResultController::index'
    _title: 'DoubleCheck Form results'
  requirements:
    _permission: 'access content'

/erlendsays/templates/doublecheck_form_result.html.twig

<p>TODO: print the form result.</p>

/erlendsays/src/Controller/DoublecheckFormResultController.php

<?php

namespace Drupal\erlendsays\Controller;

use Drupal\Core\Controller\ControllerBase;

class DoublecheckFormResultController extends ControllerBase {

  public function index() {
    return [
      '#theme' => 'doublecheck_form_result',
      '#form_result' => \Drupal::request()->getSession()->get("webform_result"),
    ];
  }

}

3
  • oh, here I have used a webform and in confirmation page settings, I chose a custom URL for showing confirmation message. Here I am expecting to use webform_submission values too in confirmation page template. Do I need to add any preprocess confirmation handler ? Oct 16, 2019 at 10:35
  • What would be the content of the message on the confirmation page? What is de flow that the user follows and how does the message add value? Oct 16, 2019 at 14:27
  • well, we send wenform submission to third party component and confirmation URL that redirected with extra parameters in querystring. So on confirmation page I need to show some webform field's data (like personalizing confirmation message) along with query parameters values Oct 16, 2019 at 15:13

Your Answer

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

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