Javascript Menu by Deluxe-Menu.com

The Fastest and Easiest-to-Use Website Forms.                Guaranteed.

Best. Website Forms. Ever.

API - Sample Code




The Formexperts API is designed to work with any programming language. The sample code below is written in PHP, if you have written sample code in other languages that you feel would benefit others, please let us know and we'll add it to the list.


Example Code

Below is a sample in PHP for the form.list using CuRL. More samples to follow.

<?php

/*********************************************************************
 * Formexperts API tester
 * Version: 1.0
 * Date: January 1, 2009
 * Author: Ian Duncan <ian@formexperts.com>
 * 
 * Copyright (c) 2009 Blue Octane Media, Inc (formexperts.com)
 *
 * Licensed under the MIT License:
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
*********************************************************************/

function sendRequest($api_url, $token, $formatted_post)
	{
	// Submit curl request
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $api_url);
	curl_setopt($ch, CURLOPT_USERPWD, $token);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $formatted_post);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return as variable
	curl_setopt($ch, CURLOPT_TIMEOUT, 4);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); // Validate SSL cert
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE);
	curl_setopt($ch, CURLOPT_USERAGENT, "Formexperts API");
	$curl_result = curl_exec($ch);
	curl_close ($ch);
	
	// fail if no result
	if (strlen($curl_result) < 2)
		return "Could not connect to server.";
		
	// return text
	return $curl_result;
	}
	
// Set defaults
$api_url = "https://secure.blueoctane.net/api/";
$token = "YOUR_API_AUTH_TOKEN";
$use_php_array = false; // set to true if you want to use the PHP array

// array of variables to post to api
$api_vars = array();  
$api_vars['request'] = "form.list";
// add additional request variables here

if ($use_php_array)
	$api_vars['method'] = "array"; 

// format the variables to send
$formatted_post = "";
foreach ($api_vars as $var => $value)
	$formatted_post .= "&" . $var . "=" . urlencode($value);

// send request and get response from API
$response = sendRequest($api_url, $token, $formatted_post);

// display the returned data
if ($use_php_array) // if using php array option
	{
	$data = unserialize($response);
	print_r($data);
	}
else 
	{
	header ("content-type: text/xml");
	print $response;
	}

?>






API Documentation


Home   |   Contact   |   Legal   |   Privacy   |   Members Area   |   Free Contact Form   |   Affiliate Program   |   Sitemap

©2017 Blue Octane Media, Inc. All rights reserved. Read Legal policy and Privacy policy.