Available on: Business plan
Formspree allows you to set up custom rules that control delivery of your form submissions, or allow you to take special actions, based on certain criteria called Triggers. Rules can be used for:
- Sending emails to different recipients based on the value of form data, such as a drop-down or checkbox input, or
- sending emails to several recipients, or
- marking submissions as spam based on content, or presence of a custom honeypot field, or
- conditionally redirecting to a different "Thank-you" page after form submit.
Here's how to get started:
Adding your first rule
By default, submissions are sent to the target email of a form. However:
If you create a rule, the form's target email is ignored, and instead the rules determine notification delivery.
We recommend that you first add a default rule that will always be triggered. You can add a default rule by following these steps:
- Click the Rules tab, then click Add Rule:
- Set the "Do" column to "Send Email" and pick a recipient email address from your verified addresses. Then click Save. Leave the condition as "Always" so that, when a new submission is received, this rule will always be triggered.
At this point, when a new submission is received, a notification email will be sent to the Target Email address. This is similar to the default functionality for Formspree forms.
Routing Emails with a form drop-down menu
Let's say you have a form with a select input, allowing visitors to choose from a few different options. For example, suppose a visitor can send feedback to either the "Housewares" or "Electronics" department. Here's what this form might look like:
Here's some form HTML that accomplishes this:
<h3>Please leave your feedback below:</h3>
<form action="https://formspree.io/f/{form_id}" method="POST">
<label>Department:</label>
<select name="department" required>
<option value="housewares">Housewares</option>
<option value="electronics">Electronics</option>
</select>
<label>Feedback:</label>
<textarea name="message"></textarea>
<label>Your Name:</label>
<input name="name" type="text" required/>
<label>Your Email: </label>
<input name="email" type="email" required/>
<button>submit</button>
</form>
The highlighted select statement above creates a drop-down menu where the user can choose either "Housewares" or "Electronics".
Adding drop-down routing rules
Let's say that you want to send notifications to the appropriate department based on the visitor's choice from the drop-down input field. To accomplish this:
- First ensure you submit the form once including the relevant input field. In this case, we need to submit the form with the "department" select input. This makes Formspree aware of the new field, so it can be used when creating rules.
- Create a new rule for one of the options in the input field. First, set the Target Email to the appropriate recipient, for example "housewares@example.com". Then choose "When a field contains a keyword" as the condition. Next, select the input field to test for a match. In this case, the "department" field. Then fill in the appropriate value from the select input. In this case, we'll use "housewares". Finally click Save.
At this point, the second rule will match if, contained in the "department" field, there is the word "housewares". When the rule matches, a notification will be sent to the Target Email, "housewares@example.com". - Now create a rule for the second option, similar to the rule above. In this case, we will send a notification to "electronics@example.com" when the "department" field contains "electronics".
At this point, when a new submission comes in, it will either match with the first or second rule, depending on whether the "department" field contains the word "housewares" or "electronics". That will cause a notification email to be sent to either "housewares@example.com" or "electronics@example.com".
Routing Emails with a checkbox
What if you have a form with a checkbox, and you want to send an email notification only when the checkbox is checked? For example, let's say your form has this checkbox:
Here's some form HTML for the checkbox above:
<label>
<input type="checkbox" name="urgent" value="yes">
My problem is urgent!
</label>
Adding checkbox routing rules
In order to send an email notification only when the checkbox is checked, add a rule using the "When a field is not empty" condition. Then select the appropriate field for the checkbox. For example:
Sending to multiple recipients
If you just want to send an email to multiple recipients, you can do so by adding multiple rules using the "Always" condition. Here's an example of a form that sends notification emails to both "electronics@example.com" and "housewares@example.com":
Catching spam with a custom honeypot field
A honeypot field is a special field that only spammers are likely to fill out. Spammers often employ bots that scrape a web page's HTML and automatically fill out any forms that are detected. However, when a form is rendered, JavaScript and CSS can be used to hide a field from human visitors, but not from bots. When a form is submitted with such a field completed, it can be confidently categorized as spam.
Formspree allows you to implement a honeypot with the _gotcha field. However, some spammers are aware of this special field, and have incorporated it into the logic of their bots.
To create a honeypot that no spammer can anticipate, you can create your own custom honeypot field with rules. First, add a field to your form, and hide it so that no human visitor will fill it out. For example, you could use the following form input.
<input type="text" name="myhoneypot" class="myclass">
Be sure to pick something unique in place of "myhoneypot". If every form has a different honeypot field, spammers can't anticipate which field is the honeypot.
Use your own custom CSS to hide the field. Again, the key is to not use a standardized approach for hiding the honeypot field so that it's more difficult for spammers to detect and avoid. As an example, here's some CSS to hide the above field:
.myclass { opacity: 0; position: absolute; }
Finally, you can add a rule that tags a field a spam when the honeypot field is filled in. Pick "Tag" in the "Do" column, and select "Spam" to tag the submission as spam. Then chose the trigger "When a field is not empty" and pick your honeypot field name.
Adding custom spam rules
Most spam should be detected by Formspree's automated filters. However, if you are receiving spam, and are able to detect patterns in the spam content, you can also create your own custom spam rules. These rules can be especially helpful if you're temporarily experiencing a large volume of spam and need to take immediate action.
To create custom spam rules, use the "Tag" action under the "Do" column and choose "Spam" to start flagging messages as spam. Then pick "When a field contains a keyword" for the trigger, and select a field that contains spammy content. Finally, include the keyword or words that frequently appear in the spammy message.
If you consistently receive a large volume of spam, and the automatic filters aren't categorizing them automatically, please reach out to us with a support request.
Conditionally redirect based on form data
When a visitor completes a form, sometimes you want to provide a different "thank-you" message depending on the form data. For example, if a visitor requests a follow-up meeting, you may want to redirect them to a calendar booking page.
To accomplish this, pick the "Redirect" option of the "Do" column and enter a full URL where you want customers to land. Then create a trigger using a checkbox or dropdown input, similar to the checkbox or drop-down sections above. Now, when users fill out your form, they will be conditionally redirected to the page you specify.
You can also use the "Redirect" action with the "Always" condition to override Formspree's default redirect behavior.
Triggering with other Conditions
So far we've discussed adding routing rules using the "Always", "When a field contains a keyword" and "When a field is not empty" Conditions.
For the later two Condition types, there are also negative Conditions: "When a field is empty" and "When a field doesn't contain a keyword".
Here is a list of all the conditions, and some scenarios when you might want to use them:
- Always: You want to send an email notification for every submission. Useful for adding multiple recipients.
- When a field is not empty: You have a checkbox or text input. Useful in scenarios when you want to follow up only with certain visitors.
- When a field is empty: Useful for opt-out checkboxes. For example, you may wish to only send a notification for visitors that don't check "Please do not contact me". Otherwise, let their feedback go directly to the archive, to be exported later.
- When a field contains a keyword: You have a drop-down or text input. Useful for routing to different recipients based on the value. Can also be used to send a notification when a particular keyword is present. For example, you may want to notify the billing department if a message field contains the word "refund".
- When a field doesn't contain a keyword: Can be used in custom spam rules to keep certain messages from being flagged as spam.