How do I use Spectate forms as form handlers?

On your website, you might have existing HTML forms that you want to keep, but still submit the data to Spectate. There are two approaches to this:

POST the data directly to Spectate from your HTML forms (client-side)

  1. Go to Manage > Forms.
  2. Click +Create Form to make a new Form.
  3. Recreate the existing form from your website. For example, if your existing form has the fields: First Name, Last Name, Company URL, Phone, Company, and Email then make Fields map to the Spectate-equivalents: First Name, Last Name, Website, Phone, Company, and Email.
  4. Expand More Options and under "Form Data Options", check the box "Allow third-party forms to submit to this form".
  5. Click Create to save the new Form.
  6. Copy the System URL for the Form (e.g. http://my.spectate.com/name-of-form ).
  7. On your website, change the action attribute in the <form>  HTML element to the System URL you just copied. For example: Change this: <form action="/submit.php" method="post"> to this: <form action="http://my.spectate.com/name-of-form" method="post"> 
  8. You'll also need to update the name attributes in the <input> elements map to the Spectate equivalent. For example: Change this: <input name="firstname" type="text" class="text-field required"> to this: <input name="first_name" type="text" class="text-field required">  See the Standard Fields in Spectate Forms table below for the standard fields and their identifiers.
  9. Save the existing form to your site.
  10. You're good to go; your form data will be submitted to Spectate!

POST the data to Spectate with your own form processing code (server-side)

You may still need to capture your form submissions initially and do some processing. After which, you want to send some or all of the captured form information on to Spectate.

First, ensure that Spectate has all of the form fields you need to store your data and create any additional custom fields necessary.

Then, in your form processing code:

  1. Grab the fields that you want to pass to Spectate from your form submission.
  2. URL encode their values.
  3. Map the values to your Spectate form field names. Refer to the Standard Fields in Spectate Forms table below for the standard fields and their identifiers.
  4. Include the _spectate_tracking_session cookie in your POST to allow successful conversion of visitors into leads. This requires that your site has the Spectate tracking code on it.
  5. Post the data to the Spectate Form's system URL (e.g. http://my.spectate.com/name-of-form ).

Here is an example PHP script that accomplishes this:

<?php
/**
 * Posts data to a Spectate form
 */
class SpectateFormHandler
{
    public function insertLeads($post)
    {
        $strPost = "";
        //create string with form POST data
        $strPost = "first_name=" . urlencode($post['first_name'])
        . "&last_name=" . urlencode($post['last_name'])
        . "&email=" . urlencode($post['email'])
        . "&phone=" . urlencode($post['phone_number'])
        . "&company=" . urlencode($post['firm_name']);

        //set POST URL
        $spFormUrl = "http://my.spectate.com/<your_form_url>";

        //Get Spectate cookie from request
        $spCookie = $_COOKIE['_spectate_tracking_session'];

        //intialize cURL and send POST data
        $ch = @curl_init();
        @curl_setopt($ch, CURLOPT_POST, true);
        @curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost);
        @curl_setopt($ch, CURLOPT_URL, $spFormUrl);
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // set the Spectate cookie in the POST request to ensure Visitor data gets associated with new Lead
        @curl_setopt($ch, CURLOPT_COOKIE,"_spectate_tracking_session=".$spCookie);
        if(curl_exec($ch) === false)
        {
           $msg = curl_error($ch);
           @curl_close($ch);
           throw new Zend_Exception( $msg );
        }
        @curl_close($ch);
    }
}
?>

Standard Fields in Spectate Forms

Spectate form field names are converted to "snake case" meaning they are converted to lower case and the words are combined with underscores (e.g. First Name > first_name ). Below are the fields that come with Spectate forms by default by name and their name  attribute.

  • Address One: address_one 
  • Address Two: address_two 
  • Annual Revenue: annual_revenue 
  • City: city 
  • Comments: comments 
  • Company: company 
  • Country: country 
  • Department: department 
  • Email: email 
  • Employees: employees 
  • Fax: fax 
  • First Name: first_name 
  • Industry: industry 
  • Job Title: job_title 
  • Last Name: last_name 
  • Notes: notes 
  • Phone: phone 
  • Salutation: salutation 
  • State: state 
  • Territory: territory 
  • Twitter Username: twitter_username 
  • Years in Business: years_in_business 
  • Zip: zip 

Note regarding Email field validation

If you are using an HTML form, know that the default HTML5 email input validation is less restrictive than Spectate's Email field validation.

To avoid errors on form submission, be sure to validate your HTML form's email input. Spectate validates emails using the following regular expression:

/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i