Our support has moved to: here

How do I use 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 Email
    • Then make Fields map to the Spectate-equivalents:
      • First name
      • Last name
      • Website
      • Phone
      • 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/some-form-we-just-made" method="post">
  8. Also on your form, you'll 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 table below for the standard fields and their names.
  9. Save the existing form 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.

The procedure is:

Then, in your form processing code:

  • Grab the fields that you want to pass to Spectate from your form submission
  • Url encode their values
  • Map the values to your Spectate form field names. Refer to the field names outlined below.
  • 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.
  • Post the data to the Spectate Form's "System URL"

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.

Field Name `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