How to post mobile numbers to a group in your account using a web form

Update: There is an easier way to post numbers to a group using our Form2SMS product

Most businesses have enquiry or order forms on their web site. This is a great way of collecting mobile numbers for later text marketing. Another use for collecting mobile numbers from a web form is for competitions where for example there may be an on pack promotion which people can text to but also a web entry form.
We have built a simple way to ‘inject’ mobile numbers into a group (you need to have already set up a group in your Text Marketer account).
What you’ll need:

  • A group name for a group that’s already been created in your account. To create a group, in your Text Marketer account, go to Manage contacts and add a new group (note: if you want to add numbers to a group for a shortcode keyword, a group may already have been created for it. It would be named using the format Short_[keyword]). Or go to Import and Upload to Group, from the drop down menu check what groups already exist in your account. Make a note of the group name for the group you want to be able to add numbers to using a web form.
  • Your API username and password (which may be different from your login details). Go to Account Settings and the API config tab to get these in your account.
  • A web form to collect the mobile number from your customers.

For those using PHP, two solutions for integrating this into a web form are provided below. After this is done, the mobile number of everyone who completes your form will be added to the send group specified.
Case 1 : Using a form we provide
You can download our PHP mobile number submission form. Copy the contents to a new PHP file (the name you give it is irrelevant) and put it on your server. You need to edit a few lines at the top of the file with the group name, API username and API password you collected earlier. If you now enter the corresponding web address that points to your new file, in your web browser you’ll see a simple web form asking you for a mobile number. If you enter a mobile number and click the submit button, it will add the number to the group you specified in the file, in your Text Marketer account.
The PHP script provided above contains a very simple form. The HTML for the form can be found at the bottom of the file. You may wish to pass this script and the details above to your web designer and they will be able to customise it to your own style.
Case 2: Integrating into your existing website form
If you already have a form on your website and you’d like to add the functionality to it so that the mobile numbers collected on your form are added to the group in your Text Marketer account, you can use this PHP include file. Change the .txt extension to .php and put the file in your includes folder.
To use the file, let’s say your web form contains an input text box named ‘mobile’ and the form action points to a file called submit.php. In your file submit.php you will simply add these lines of code: 

include_once ('');
// TODO change these!
$username = 'myAPIusername';
$password = 'myAPIpassword';
$groupName = 'myGroupName';
$groupAdder = new TMGroupAdd($groupName, $username, $password);
$success = $groupAdder->add($_REQUEST['mobile']);

Change the username, password and group name values with the details you gathered earlier. You can use the boolean variable $success to determine whether the add was successful or not.
For more advanced details about the data that is returned when you add a number to a group, see the REST API documentation.