Smart Form Java Script API

With Single Script Smart Forms you have the ability to change features on said form which enhance the user experience. These can be showing or hiding elements when submitting a form, pre-populating of fields for users, and even setting events to store cookies independently of Gator.

Functions

Name Description Explanation Argument Example
_gf.on() 
Provide an event callback to be run at key points during a form’s submission process.  

‘submit’ – when the form has been submitted by the user and is about to be posted to GatorMail. 

 

‘success’ – when the form was successfully submitted to GatorMail. 

 

‘failure’ – when the form was submitted to GatorMail but an error occurred.  

 

‘complete’ – runs after either a successful or failed submission.  

Please note providing ‘success’ and ‘failure’ callbacks will stop the respective success/failure messages from showing up on the form

formId – the id of the form this callback should be used with. 

 

eventName – the name of the event that should trigger this callback (‘submit’, ‘success’, ‘failure’, ‘complete’). 

 

callback – the callback function to be run when the event is triggered.  


_gf.on(12, ‘submit’, function() { 

  // do something here 

}); 

 

_gf.on(12, ‘success’, function() { 

  // do something when submitted successfully 

}); 

 

_gf.on(20, ‘success’, function() { 

  // do something when form 20 is successfully submitted 

}); 


_gf.findForms()

Get Smart Forms Single Script to rescan the page for newly added smart form tags. 



This is best used if the form tags are added to the DOM after initial page load, such as on a Single Page Application (SPA) or in a modal.


-- _gf.findForms();
_gf.setFieldDefault()
Set a default value for any field on a Smart Form.
This can be used for both visible and hidden fields.

Set a default value for any field on a Smart Form. 

formId – the id of the form the field is on.

fieldName – the name of the field (this should match up with the name of the field set in GatorMail).

defaultValue – the value to set represented as a string. Set Date values in the format “yyyy-MM-dd”.


_gf.setFieldDefault(12, ‘my_custom_text_field’, ‘my default value’); 


_gf.setFieldDefault(12,

‘my_custom_number_field’,

’30’);


_gf.setFieldDefault(12, 

‘my_custom_truefalse_field’,

‘true’);


_gf.setFieldDefault(12, 

‘my_custom_date_field’,

‘2019-12-25’);


Properties

Name Description Explanation Example
_gf.f.forms
Array of all forms enabled for Smart Forms Single Script.
Can be used to see all data included in each form.
console.log(_gf.f.forms);
_gf.c
Array of event callbacks to be consumed by Smart Forms Single Script when it is fully loaded.

Define _gf yourself with c as an array of callbacks on the DOM as an alternative to _gf.on(). The Smart Forms Single Script will find this and pick up these callbacks.

 

Provide each callback as an array itself, with formId, eventName, callback in that order.

var _gf = { c: [

   [12, ‘submit’, function() { 

     // do something here

  }]

]);

 

var _gf = { c: [

   [12, ‘success’, function () {

     // do something on success

  }], 

 [15, ‘success’, function () {

   // do something else for form 15

 }]

]};

If you experience any issues with this functionality, please contact support@communigator.co.uk