Use the Twilio add-on to send an SMS/text message when a form is submitted or when an entry is updated. You may also allow users to text in their votes for a poll or survey created by Formidable Forms. Each received text message will automatically create a new entry in your form. Please note, you must have a Twilio account in order to use the Twilio add-on.
Download and Install
- If you haven't already, install and activate the current version of Formidable Forms Premium on your WordPress site.
- After confirming your Formidable Forms license, proceed to the Formidable → Add-Ons page and click the Install button for the Twilio SMS plugin for WordPress.
Set up the Twilio SMS forms
- Log in to your Twilio account and go to Account → Keys & Credentials → API keys & tokens.
- In the API keys & tokens page, copy your Twilio Account SID and Auth Token. If you are using a trial account, you must verify the number you are sending to.
- Go back to your Formidable → Global Settings → Twilio page and insert your Twilio Account SID and Auth Token.
Phone Formatting
When setting up your Phone Number field format, Twilio recommends using E.164 number formatting for all To and From phone numbers to ensure deliverability. Learn more about Twilio Phone Number formatting.
The E.164 formatted phone numbers can be written as:
[+][country code][area code][subscriber number]
For example, this is the recommended format for a US phone number.
+14188884567
Send international SMS messages
Twilio lets you send text messages to many countries worldwide. By setting up SMS Geo Permissions, you can choose which countries you want to send messages to. To protect against fraud, Twilio recommends turning off message sending to countries your business doesn't use or rarely uses.
When you first create an account, you can automatically send messages to the country associated with the phone number you used during signup. Follow the instructions below on how to change the SMS Geo Permissions.
- Log in to your Twilio Account where you want to change the permissions.
- Navigate to Console → Messaging → Settings → Geo Permissions.
- Scroll through the list and find the country where you want to turn the SMS Geo permissions on or off. When you find the country, select the checkbox next to its name or use the Filter by Country search box.
- Click the Save Geo permissions button to save your changes. Learn more on setting up SMS Geo permissions with Twilio.
Send text message on form submission
You may send an SMS text message as an autoresponder when a Formidable form is submitted or when an entry is updated. Please follow the directions below to set this up.
- Create a form that will be used to send text messages. Include a Phone Number field in your form if you would like to send the message to the user filling out the form.
- Go to your form Settings → Actions & Notifications tab. Click on Twilio to add a Twilio action to your form.
- Give your Twilio form action an Action Name for easy reference. This action name will only be seen on the back-end.
- Select one or more actions in the Trigger this action when dropdown.
Different triggers will be visible depending on which add-ons are active. The User Registration add-on adds an option to send a text after a user successfully registers. The PayPal and Stripe forms add-ons add an option to send a text when a payment is completed. - Insert a phone number or your Phone Number field ID in the To box. You may insert multiple phone numbers, separated by a comma. A separate text will be sent to each phone number.
- In the From box, you have the following options:
- All numbers in the linked Twilio account. Choose one of these for live sending. These numbers are cached in the dropdown for 15 minutes. If you need it cleared sooner, choose the number linked from the Twilio account.
- The Twilio Test number. A test number can only send to another test number.
- Use a different Twilio phone number. Don't add a custom number unless you know what you're doing. Be sure to include the international code.
- Use the [default-message] shortcode in the Message box when sending in an SMS message. This will send a message like: Sent from your Twilio account. Your responses were successfully submitted. Thank you!
If you want to customize your own message, enter the message that you would like to send in the Message. Click on fields in the Customization panel to add field values from the entry into your message. - If you would like to conditionally send a text message, you will need to add Conditional Logic. You may choose to send a text message only when a user agrees to receive text messages, for example. Please note that Conditional Logic is only available in the Pro version of Formidable Forms.
- Click Update. Now when a user submits or updates an entry, a text message will be sent to the specified recipient.
Please note that you must configure the Global Twilio settings in order for this to work correctly.
Set up text voting
Use Twilio to allow users to text responses to a poll or survey. The responses will be stored in your form's entries.
- Create a poll or survey with Formidable Forms. This form can have only one survey question. We also recommend including a text field to act as a catch-all for invalid votes.
- Log into your Twilio account and go to the Phone Numbers page.
- Find the phone number that you will be using to accept text votes. Click on the phone number so you can edit the messaging configuration.
- Select Twilio SMS as the messaging service.
- Configure with Webhook, TwiML Bin, Function, Studio Flow, Proxy Service
- Select Webhook when a message comes in and HTTP POST as the HTTP. Change the Messaging URL to:
your-site-url/wp-admin/admin-ajax.php?action=frm_twilio_vote&form=5
Replace your-site-url with your own site's URL. Change 5 to the ID of your form.
- When the user texts their vote to your Twilio phone number, the text message content will be saved to your poll or survey form's entries. Your users can either text the number position of the choice in your form or the word itself. For example, if I have a poll for favorite colors and my choices are Red, Green, Pink, and Blue, and my favorite color is pink, then I can text any of the following:
- 3
- Pink
- pink
- PINK
Send texts to a phone number list
If you would like to send texts to a list of phone numbers that have been entered in a Formidable form, follow the steps below.
- Create a view that is connected to the form where phone numbers are stored. We'll call this the Numbers View. The View will need to be set up to display All Entries.
- In the Content box insert the following code;
[x],
Replace 'x' with the ID of your phone number field. Click Update.
- Create a new form, this is the form that will be used to send out messages, call this your Send SMS Form form. Add any fields you would like to use and click Update
- Follow the steps here to create your Twilio action.
- In the To box, insert the shortcode for the Numbers View.
[display-frm-data id=x]
Replace 'x' with the ID of the Numbers View.
- In the Message box, insert the message you would like to send upon submission. Use the customization panel to insert field values. Click Update
- Publish your Send SMS Form on a page. It is recommend to change the Visibility to Private or Password Protected so only specific users can send texts to the Phone Number list.
Click Update. - Now when you fill out the Send SMS Form form and hit submit, it will send out the message to all the phone numbers saved in the Numbers Form.
Filtering phone number list
If you would like to send text messages to a filtered phone number list, using a parameter is useful. For this example, you can send text messages to users that have more than a certain number of points in their account.
- Before proceeding, you will first need to create the Numbers View.
- Go to edit your View.
- Scroll down to the Advanced Settings. In the Sort & Filter section click the + Add button next to Filter Entries. Set up the filter so it says "Points is greater than [get param=points]"
- Click Update to save your View.
- When inserting the View shortcode, add a param with the value from the field.
[display-frm-data id=62 points="[100]"]
The value in field 100 will be sent to the View and used in the filter. Swap out 62 for the ID or key of your View.
Related customizations
Undo phone formatting
When a phone number is prepared in this plugin, it is forced to be numeric. But if you are using a Twilio alphanumeric phone number, you will need to reverse this automatic formatting.
add_filter( 'frmtwlo_format_number', 'format_twilio_num', 10, 2 ); function format_twilio_num( $num, $args ) { return $args['original']; }
Save phone number in a field
By default, the phone number is stored as the IP address for Twilio submissions. This example copies the value into another field.
add_filter( 'frm_validate_field_entry', 'copy_twilio_phone_number', 10, 3 ); function copy_twilio_phone_number( $errors, $posted_field, $posted_value ){ if ( $posted_field->id == 25 && isset( $_POST['ip'] ) ) { //change 25 to the ID of the phone field $_POST['item_meta'][$posted_field->id] = $_POST['ip']; } return $errors; }
Troubleshooting
No SMS message received
- Are you using a Twilio trial account? If so, did you verify the number you are sending to?
- Does the From number in your form settings match the number in your Twilio account? You must send from a Twilio number.
- If you are outside the USA, you must include an international code on the phone numbers. If these are missing, the USA code is used.
- SMS messages will not send if you are using test API credentials. The live credentials are required.
Twilio alphanumeric sender
At this time, sending from an alphanumeric id is not supported. Unfortunately, Twilio does not support this feature in the USA, so our developers are not able to test or support it.
Error messages
Sorry, there was an error saving your vote.
This message is shown in two cases.
- The form ID in your Twilio API URL isn't a valid form id.
- Your form is set to only allow logged in users to submit.
Sorry, you can only vote once.
This message is returned when your form is limited to one response per user, and this phone number already has a submission in this form.