Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff-2887375-17-18.txt | 626 bytes | Nitebreed |
#19 | alterSettings-2887375-18.patch | 2.32 KB | Nitebreed |
| |||
#17 | interdiff-2887375-12-17.txt | 1.71 KB | Nitebreed |
#17 | alterSettings-2887375-17.patch | 2.27 KB | Nitebreed |
#12 | alterSettings-2887375-12.patch | 2.05 KB | Nitebreed |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedEmail 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)
Comment #3
howdytom CreditAttribution: howdytom as a volunteer commentedJacob, 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.
Comment #4
howdytom CreditAttribution: howdytom as a volunteer commentedComment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer commented@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...
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedComment #7
NitebreedConditional 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?
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedYes, it could be done using a contrib module.
Comment #9
NitebreedAlright, then I'll go and port that one to 8 then :)
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedHmm.... 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.
Comment #11
NitebreedOk, I'll look into that direction then
Comment #12
NitebreedAfter 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:
See attached patch
Comment #13
NitebreedComment #14
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI 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.
Comment #15
NitebreedThis 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.
Comment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented::preSave should be conditionally triggered.
For now, I don't want to add any additional hooks or methods unless they are absolutely needed.
Comment #17
NitebreedI 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.
Comment #19
NitebreedTest failed due to when loading the settings form, there's no submission yet available. New patch attached.
Comment #20
NitebreedComment #21
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@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.
Comment #22
NitebreedSounds good!
Comment #23
Syntapse CreditAttribution: Syntapse as a volunteer commentedi 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
Comment #24
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@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.
Comment #25
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedPlease see #2926536: Provide a settings handler that makes it easier to tweak the confirmation page and preview.
@Nitebreed Your patch from #19 was very helpful.
Comment #26
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented