Sending webform submissions to email based on value of field

We recently did a site for a client that allowed patients to submit a webform to request an appointment. The user could choose their physician and based on their choice, the submission would be emailed to the chosen doctor’s secretary. I originally thought about using the key part of the key|value pair for the select list to store the secretary’s email address, with the doctor’s name. This wouldn’t work, however, because the key could not contain standard email address characters. The solution involved isn’t exactly dynamic, but for a select list that won’t change much (the case here), it’s a fairly elegant solution. Here is the select list and associated code. I created this with the webform UI using a simple select list webform field.

select_list_code

Next, is a screenshot of the webform “email settings.” (click for a larger view):

email_settings_webform

Basically, I’ve added a line to the bottom of every email that contains a specific string followed by the doctor chosen. Because the string will look the same every time, we are then able to use regular expressions to get the chosen doctor. Using hook_mail_alter, we can then modify the email ‘to’ address based on the doctor chosen.

Tagged with: , , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*