Quick Start

This quick start tutorial includes examples and templates, covering the form synergy's dynamic web API and JavaScript client.

Create a Form Synergy Account

Integrating Form Synergy into your app or website can begin as soon as you create an account.

Sign in Create an account
Create a Form Synergy Account

Installing the Library

The PHP library can be installed via composer:

		
composer require form-synergy/php-api
		

Alternatively, you can download the source directly.

Access API documentation through the sidebar, or see the source on GitHub.


Setting up the API
				
// To use the bindings, use Composer's autoload
require_once('vendor/autoload.php');

// For manual installation
require_once('/path/to/form-synergy/php-api/api-client.php');

/**
 * Initiate session storage.
 */
\FormSynergy\Session::enable();

/**
 * Import the class.
 */
use \FormSynergy\Fs as FS;

/**
 * The Configuration
 */
FS::Config([
	'version' => 'v1',
	'protocol' => 'https',
	'endpoint' => 'api.formsynergy.com',
	'apikey' => $apikey,
	'secretkey' => $secret,
	'max_auth_count' => 15,
]);

/**
 * Create a local storage directory, to store downloads and results.
 */
FS::Storage( __DIR__, 'local-storage' );

/**
 * Load profile.
 */
$api = FS::Api()->Load($profileid);
				
Setting up the API

API Reference
Test request

To make sure our settings are correct and a connection has been established, we can create a profile request

		  
$api->Get('profile')
    ->Where([
        'profileid' => 'Your Profile ID'
    ])
    ->As('profile');

if( $api->_profile() ) {
    echo 'Profile ID: ' . $api->_profile('profileid') . ' exists';
}
		  
Response

If all went well, the response should look like this.

{
    "profileid": "profile-cw56xxcxxxfd343325cdf",
    "email": "...",
    "address": "...",
    "city": "...",
    "companyname": "Company Name",
    "state": "...",
    "zip": "00000",
    "phone": "000 000 0000",
    "lname": "...",
    "fname": "...",
    "country": "..."
}
			

API Reference
Register and Verify a Website

To get started we must first create a request and add the desired website or domain.

Using the API

1) Create a Website

			
 $api->Create('website')
    ->Attributes([
        'proto' => 'https://',
        'domain' => '...com',
        'name' => 'My Website',
        'indexpage' => '/'
    ])
    ->As('website');
 
 // The response is now stored as Website.
 $website = $api->_Website();
 
 // To retrieve a property from the stored response:
 $siteid = $api->_Website('siteid');
 			

2) Meta Tag

We have successfully created a website, to enable service on this website, it must be verified.

	
// The following meta tag must be present before the </head> closing tag, or verification will fail!
<meta name="fs:siteid" content="web-db56b95bfe08cb778b25a5982d01bb4a"/>			

		

3) Verify the Website


$api->Get('website')
    ->Where([
        'siteid' => $api->_website('siteid')
    ])
    ->Verify()
    ->As('siteVerification');
	
	
Using the Console
Register a Website Verify a Website

API Reference
Creating a strategy

Each strategy contains it’s own set of rules, modules, objectives and behavior. Although each website can have multiple strategies, only one can be enabeld.

Now that we have successfully verified our website, we need to create a strategy.

$api->Create('strategy')
    ->Attributes([
        'siteid' => $api->_website('siteid'),
        'name' => 'Default Strategy'
    ])
    ->As('strategy');
			

API Reference
Creating modules
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

$api->Create('module')
    ->Attributes([
        'name' => 'Contact Us',
        'modid' => $modid,
        'siteid' => $siteid,
        'form' => [
            [
                'x' => 0,
                'type' => 'text',
                'system' => 'fname',
                'label' => 'First Name',
                'name' => 'fname',
                'class' => 'form-control'
            ],
            [
                'x' => 1,
                'type' => 'text',
                'system' => 'lname',
                'label' => 'Last Name',
                'name' => 'lname',
                'class' => 'form-control'
            ],
            [
                'x' => 2,
                'type' => 'email',
                'system' => 'email',
                'label' => 'Email Address',
                'name' => 'email',
                'class' => 'form-control',
                'validation' => 'yes'
            ],
            [
                'x' => 3,
                'type' => 'tel',
                'system' => 'mobile',
                'label' => 'Phone Number',
                'name' => 'mobile',
                'class' => 'form-control',
                'validation' => 'yes' // Enable validation
            ],
            [
                'x' => 4,
                'type' => 'textarea',
                'system' => 'custom',
                'label' => 'Message',
                'name' => 'message',
                'class' => 'form-control h-3' // <- Add class name h-3 for height: 3rem;
            ]
        ],
        'headings' => [ // Add multiple headings to alternate between headings.
            [
                'subject' => 'Subject 1',
                'body' => 'Message body 1'
            ],
        ]
    ])
    ->As('CreateModule');

 
                            
                            
{
    "lastused": "2019-02-27 16:25:47",
    "profileid": "profile-c2300300a5075ee8adae51da57c39f90",
    "moduleid": "module-a333c5a55d468092d4209efec3a50b88",
    "modid": "mod-d2bee61964ff44202fde3f2d315317b7",
    "siteid": "web-169b185e8dc05ad610a6e3a50a6e3712",
    "name": "Contact Us",
    "form": [
        {
            "x": 0,
            "type": "text",
            "system": "fname",
            "label": "First Name",
            "name": "fname",
            "class": "form-control"
        },
        {
            "x": 1,
            "type": "text",
            "system": "lname",
            "label": "Last Name",
            "name": "lname",
            "class": "form-control"
        },
        {
            "x": 2,
            "type": "email",
            "system": "email",
            "label": "Email Address",
            "name": "email",
            "class": "form-control",
            "validation": "yes"
        },
        {
            "x": 3,
            "type": "tel",
            "system": "mobile",
            "label": "Phone Number",
            "name": "mobile",
            "class": "form-control",
            "validation": "yes"
        },
        {
            "x": 4,
            "type": "textarea",
            "system": "custom",
            "label": "Message",
            "name": "message",
            "class": "form-control h-3"
        }
    ],
    "headings": [
        {
            "subject": "Subject 1",
            "body": "Message body 1"
        }
    ],
    "success": "Success Message",
    "dismiss": "Dismiss Message",
    "delay": 0,
    "buttonsdisabled": "no",
    "buttonsubmit": "Submit",
    "buttondismiss": "Dismiss"
}
                            

API Reference
Creating Objectives

An objective allows us to configure specific rules limited to it’s parent strategy, allowing access to it’s resources, such as modules, behaviors, form properties… More about Objectives

		
$api->Create('objective')
    ->Attributes([
        'siteid' => $api->_strategy('siteid'),
        'modid' => $api->_strategy('modid'),
        'label' => $api->_modules('contact-form')['name'],
        'properties' => [
            'fname' => [
                'value' => 'yes'
            ],
            'lname' => [
                'value' => 'yes'
            ],
            'email' => [
                'value' => 'yes',
                'confirmed' => 'yes'
            ],
            'mobile' => [
                'value' => 'yes',
                'confirmed' => 'yes'
            ]
        ],
        'limittomodule' => $api->_modules('contact-form')['moduleid'],
        'notificationmethod' => 'email',
        'recipient' => [
            'fname' => 'Jhon',
            'lname' => 'Smith',
            'email' => 'jsmith@demo.interactionapi.com',
        ]
    ])
    ->As('objective');
		
Create an objective

Front-end implementation

Assuming all went well, let’s get started with the front implemantation.

javaScript API