I have raised a question on Drupal Answers related to my feature request.

Basically, it'd be nice to have a possibility to map different emails against different "select" component options (see attachment).

This would be very helpful when you want to send an email notification to different addresses depending on a user selection but you don't want to have an email as a component value(s).

Clipboard02.jpg101.72 KBVlad Stratulat


Vlad Stratulat created an issue. See original summary.

Vlad Stratulat’s picture

Issue summary: View changes
jrockowitz’s picture

This would be great feature to add to the YAML Form module. There are some more important features and issues that need to be addressed first.

There should be some relatively easy way to do this via code. For example, you could use a hidden element or value for the email destination and change the element's via using a hook_form_alter and maybe an '#element_validate' handler.

Maybe someone can post a recipe here.

Vlad Stratulat’s picture

I was trying to achieve this myself but the only thing I was able to achieve is to add input fields corresponding to the component's options. However, when I was filling the fields with emails and submitting the form, none of them were saved.

I need to learn D8 more (that's what I'm doing at the moment) so that I understand how it's working.

fenstrat’s picture

Project: YAML Form » Webform
Version: 8.x-1.0-beta20 » 8.x-5.x-dev
jrockowitz’s picture

andypost’s picture

Issue summary: View changes

Looks handlers supports config forms \Drupal\webform\WebformHandlerInterface with \Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm() method

dhansen’s picture

I think the best way to approach this might be to add conditional logic to handlers/emails in a similar way we have it on fields.

The use case I'm encountering is a contact form where the user can submit sales, support, and billing queries. Not only do the emails go to different places based on the type, but there is a handler that pushes user info into the company's CRM for sales inquiries only. Field-based conditional logic on the handler would make that possible.

Admittedly, this does make the original use case a little more complicated because it would mean a different email/handler for each value. What we'd lose in ease of use, we'd gain in flexibility though sometimes that's not always a great trade.

jrockowitz’s picture

I think we have to implement the simpler use case and then consider improving conditional logic handling. Right now, we are just using the #state API which is a client side library. We might be able to leverage and/or extend Core's Condition Plugin System.

jrockowitz’s picture

I needed to start a dedicated ticket with an implementation plan to get this feature rolling.

@see #2854021: Send email based on element options selection

I think conditional routing of emails might be something that the Rules module can handle.

jrockowitz’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ashish_6888’s picture

Is this possible with Drupal 8. Because it seems like it is Drupal 7.

jrockowitz’s picture

@ashish_6888 This feature is now available with Webfrorm 8.x-5.x.

ashish_6888’s picture

I am trying to set the email on the basis of selection of select box value. For ex: select box has two values
1. IT
when i select IT the form should be submitted to ithelpdesk@abc.com and when i select SALES the form should submit to sale_enquiry@xyz.com. I have achieved this using webform in Drupal 7, But i am not able to find any option to achieve the same in Drupal 8.
can you please tell me how i can do this using Drupal 8.

Many Thanks in Advance!!