Hi there,

I am trying to set up a event registration to collect a couple of attendees. I’ve set up '#type': radios YES/NO selection to do that.

Now, how can I show a different confirmation message and send out a confirmation email based on the selection? Something like that...
A: Looking forward to see you....
B: See you next time...

Since Webform 8 it is possible to easily send out confirmation messages. I’ve went through all Webform 8 settings but couldn’t find any option for additional conditions (if/else) to realise that. Do I still need Rules to do that?

Thanks for your help.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

howdytom created an issue. See original summary.

jrockowitz’s picture

Status: Active » Fixed
FileSize
80.61 KB

Email handlers support routing emails based on #options.

Below is a screenshot from the Feedback template's notification email handler. (/admin/structure/webform/manage/template_feedback/handlers)

howdytom’s picture

Jacob, thank you for your super-fast reply!! Yes, I saw that option, too. This not quite I am looking for. It’s similar to conditions in Webform 7.

If User A selects YES ——> a confirmation message e.g. »Looking forward to see you…« should show up. Also, a confirmation email to his/her email address email with the same text would be nice.

Same goes with User B. If User B selects NO ——> a confirmation message e.g. »See you next time…« should show up. Also, a confirmation email to his/her email address with the same text would be nice.

I hope this makes sense.

howdytom’s picture

Status: Fixed » Needs review
jrockowitz’s picture

@howdytom You are going to have alter the email via code.

@see https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-pr...

jrockowitz’s picture

Status: Needs review » Closed (works as designed)
Nitebreed’s picture

Title: How to show different Confirmation message and send out a confirmation email based on selection? » How to show different confirmation messages?
Status: Closed (works as designed) » Active

Conditional emails are possible yes, but I haven't yet found a way to specify conditional confirmation messages. In Drupal 7 this was possible with the following contrib https://www.drupal.org/project/webform_conditional_confirmation

Or am I missing someting?

jrockowitz’s picture

Yes, it could be done using a contrib module.

Nitebreed’s picture

Status: Active » Closed (works as designed)

Alright, then I'll go and port that one to 8 then :)

jrockowitz’s picture

Hmm.... You might be able to create a CustomConfirmationWebformHandler that overrides confirmation settings/behaviors based on conditional logic.

@see \Drupal\webform\WebformSubmissionForm::confirmForm
@see \Drupal\webform\Plugin\WebformHandlerInterface::confirmForm
@see \Drupal\webform\Plugin\WebformHandlerInterface::preprocessConfirmation

Below are some new methods that would allows to safely override the default confirmation message settings.

@see \Drupal\webform\Entity\Webform::setOverride
@see \Drupal\webform\Entity\Webform::isOverridden
@see \Drupal\webform\Entity\Webform::setSettingsOverride
@see \Drupal\webform\Entity\Webform::setSettingOverride

I would be open to implementing any small tweaks that make a CustomConfirmationWebformHandler possible.

Nitebreed’s picture

Status: Closed (works as designed) » Active

Ok, I'll look into that direction then

Nitebreed’s picture

After some research and discussion with colleagues I ended up by implementing a custom webform handler that makes it possible to fill in a confirmation message. Since handlers already have support for conditions, this was for us the easiest and quickest way.

This also needed some changes in webform itself. I ended up by creating a patch that makes it possible to alter settings within the WebformMessageManager class, but made it general so it can easily be reused for other purposes. Then, in my custom webform handler, I implemented the newly created method:

/**
   * {@inheritdoc}
   */
  public function alterSettings(&$webform_settings) {
    $webform_settings['confirmation_message'] = $this->configuration['confirmation_message'];
  }

See attached patch

Nitebreed’s picture

Status: Active » Needs review
jrockowitz’s picture

I don't think we need this new handle method.

Since you can access the Webform entity from within the handler you should be able to use...

$this->getWebform()->setSettingOverride('confirmation_message', $this->configuration['confirmation_message'])

... and call this code from \Drupal\webform\Plugin\WebformHandlerInterface::postSave.

Nitebreed’s picture

This won't work, because it'll override the setting in general. In our case, we will have different of those 'confirmation' handlers and determine based on conditions what the specific confirmation message for the submission should be.

jrockowitz’s picture

::preSave should be conditionally triggered.

For now, I don't want to add any additional hooks or methods unless they are absolutely needed.

Nitebreed’s picture

I tried both ::preSave and ::postSave, but I don't see any change in the message itself then. So I might be looking in the wrong direction, but can't get it to work using your suggestions.

So I went back to my original patch, but noticed the handlers were always executed, even if the conditions didn't match. I dived deeper and found that conditions are only checked if the webform submission itself was added as an argument. Here' an updated patch.

Status: Needs review » Needs work

The last submitted patch, 17: alterSettings-2887375-17.patch, failed testing. View results

Nitebreed’s picture

Test failed due to when loading the settings form, there's no submission yet available. New patch attached.

Nitebreed’s picture

Status: Needs work » Needs review
jrockowitz’s picture

@Nitebreed I am thinking about adding a new "Settings Override" handler that would allow form builders to conditionally override any webform setting based on a conditional logic. This handler would work similar to the recently added 'Action' handler which conditionally override/alters a webform submission.

Nitebreed’s picture

Sounds good!

Syntapse’s picture

i would like to vary the submit redirect depending on where/how the form is used. is that possible?

is this something site builders can control from the ui?

will this be part of the next available release?

thanks

jrockowitz’s picture

@laurencefass This a new feature which has not been created yet and may not address your immediate use case. You might want to consider writing some custom code.

jrockowitz’s picture

jrockowitz’s picture

Status: Needs review » Closed (outdated)