This tutorial explains how to set up your Participants Database signup submission notification so that the email goes to a different recipient based on a value in the submission.
In this example, the person filling out the signup form is going to make a selection in the form (let’s say with a radio button) that determines what “kind” of signup it is. When the signup is submitted, a notification email will be sent to a different recipient based on which selection the person made when filling out the signup form.
It is possible to use a similar setup to to determine the notification recipient based on any value in the submission. For example, the value of an address field to route the email according to where the person signing up is located.
Another possibility is that you have multiple signup forms on your site, but each one is for a different thing. In this case it’s a good idea to set up a Dynamic Hidden Field that captures the name of the page the signup form is on. You would then use the value in that hidden field to determine who gets the notification.
Setting up the Selector
For this example, we are using a radio button field to give the person signing up a way to select the “type” of submission it is. That field could be configured like this:
Customizing the Plugin
In the plugin example I provide below, there are several things you will want to customize for your particular purpose. First, you need to provide the name of the field that will be used to determine what the recipient will be.
In our example, it is the name of the “department” selector field that is included in the signup form.
If you’re using the address example, it might be the “city” or “country” field. For the example of a different recipient for different signup forms, the name of the hidden field you set up.
Routing the Notification
When the submission comes in, you will be using a value in the routing field to determine the recipient. The example uses a “switch” structure to do a different thing for each possible value. The switch makes it very easy to set up your routing. For example, both “sales” and “returns” are going to the same person, while the other selections each have their own recipients.
Importantly, we set up the fallback value before the switch so that if the submitted routing value does not match any of the specified selections, the notification will at least go to someone. This will be the notification recipient as defined in the template or settings.
Setting up the Recipients
In the switch statement, you can clearly see how we match the submitted value, and the set the recipient according to that match. We set the recipient value using the standard “Name <email>” format in our example, but you can also just put in the email address.
The Example Plugin
Here is the code for our example plugin. It should be easy for you to modify this to your purpose, I tried to explain each thing it does and how you can change it.
For more advanced customizations (a lot is possible here) read the section on using the pdb-before_signup_thanks action to customize other aspects of the thanks messaging that happens after a signup submission.
Not sure how to use this code? Read: How to Install a WordPress Plugin from a Gist