Web Hooks: JavaScript API & Syntax Guide
Web Hooks are executed within a sandboxed Node.js server. There are several functions exposed that will give you access to set and get form field values and several other functions to set cookies, do redirects, log messages and more.
Code Hints in the Editor
When writing your Hook using the Web Hook Editor, code hints will pop up to show you the available functions and make writing web hooks easier. Typing the following will show available code hints:
Typing "form." provides access to two key functions form.getValue() and form.setValue() as well as many other helpful functions for checking the mode the submission is running in, setting a redirect URL, or aborting a submission* (*Before Submit Mode only)
Typing "window." will display functions that can be used to set/get cookies, and access the location and query string variables
Typing a "[" character will show a list of wildcards available that can be inserted.
NOTE: If the Card Code is used in your form, it is not included in the list of wildcards as the Card Code is never recorded to the database due to PCI compliance. See Core Functionality and Syntax below for guidelines on referencing the Card Code.
Utility Functions
In addition to the Logiforms API functions, the UnderScore JavaScript Utility Library is included as a convenience and to provide some utility functions. See the website link above for a list of available functions. These functions can simply be called like:
Core Functionality and Syntax
Function | Availability | Description |
---|---|---|
form.getValue('[Field]') | *Before Show, Before Submit, After Submit |
Returns a form field value. This method should be used anytime you want to reference a form field value. *When used in Before Show Hooks, corresponding URL params will be returned instead. This can be written in any of these 3 ways:
form.getValue('[City]'); form.getValue([City]); form.getValue('field32423414134'); // by id reference Sample:
if (form.getValue('[City]')=='vancouver'){ log('City is Vancouver'); } NOTE Example: form.getValue('[City]')
|
form.setValue('[Field]','value') | *Before Show, Before Submit, After Submit |
Sets the value of a form field and updates the database with the new value. *When used in Before Show Hooks, this method sets URL parameters to pass into the form to pre-populate the form with the values supplied. This can be written in any of these 3 ways:
form.setValue('City','Vancouver'); form.setValue([City],'Vancouver'); form.setValue('field32423414134','Vancouver'); // by id reference
Sample:
if (form.getValue('[City]')=='vancouver'){ form.setValue('[City]','VAN'); form.setValue('[wheather]','RAIN') }
|
form.setRedirect('') | Before Show, Before Submit, After Submit |
Set a redirect URL. When set, the user will be redirected to this URL once the web hook is finished executing.
form.setRedirect('http://www.yourwebsite.com/') For a Before Submit Hook, form.abortSubmission() must also be called in order to redirect before the data is written to the database. If omitted, the redirect will happen after the form submission is written to the database. to pre-populate the form with the values supplied. |
form.abortSubmission() | Before Submit |
Calling this method will abort the submission. This should be used in conjunction with form.setRedirect() to redirect the user after aborting the submission.
form.abortSubmission()
|
window.setCookie('name','value','expires') | Before Show, Before Submit, After Submit |
Sets a cookie. The expires argument is optional and defaults to 30 days.
window.setCookie('age','form.getValue([age]')) // expires in 30 days window.setCookie('age','form.getValue([age]',60)) // expires in 60 days window.setCookie('age','form.getValue([age]'),'NEVER') // never expires window.setCookie('age','form.getValue([age]','NOW')) // remove a cookie |
window.getCookie('name') | Before Show, Before Submit, After Submit |
Returns a cookie by name. Returns null if the cookie does not exist.
window.getCookie('age') |
Environment Variables
Function | Availability | Description |
---|---|---|
window.querystring() | Before Show, Before Submit, After Submit |
Returns the Query String |
window.usweragent() | Before Show, Before Submit, After Submit | Returns the User Agent String |
window.remote_addr() | Before Show, Before Submit, After Submit | Returns the respondents IP address |
window.referer() | Before Show, Before Submit, After Submit | Returns the referring URL |
Helper Functions
Function | Availability | Description |
---|---|---|
form.isFormView('FormViewName:ID') | Before Submit, After Submit |
Can be used to test if the submission is being executed from a Form View. Within the Web Hook Editor, all available Form Views are listed when "form." is typed and can be inserted and used. The name and ID reference passed to the function should not be modified. Example:
if (form.isFormView('Confirm Registration View:20')){ form.setValue('[registrationDate]','10/11/2014'); } Returns true/false |
form.isUpdate() | Before Submit, After Submit | Checks if the operation is an update to an existing record or a new form submission. Returns true|false |
form.isInsert() | Before Submit, After Submit | Checks if the operation is a new form submission. Returns true/false |
form.isDeployedMode() | Before Submit, After Submit | Is the form running in a standard form submission process. Returns true/false |
form.isRespondentUpdateMode() | Before Submit, After Submit | Is the form running in Respondent Update Mode. Returns true/false |
form.isApprovalMode() | Before Submit, After Submit | Is the form running in Approval Mode. Returns true/false |
form.isRecordDetailsMode() | Before Submit, After Submit | Is the form being submitted from the Record Details Window. Returns true/false |
form.isWorkFlowEmbeddedForm() | Before Submit, After Submit | Is the form being submitted from a form embedded on a WorkFlow page. Returns true/false |
form.isWorkFlowLinkedForm() | Before Submit, After Submit | Is the form being submitted via a WorkFlow link. Returns true/false |
form.isWorkFlowEditPage() | Before Submit, After Submit | Is the form being submitted via a WorkFlow Profile Eidt Page |
form.isWorkFlowProfileEdit() | Before Submit, After Submit | Is the form being submitted via a WorkFlow Edit Page |
0 Comments