Docs / API & Plugin Development / Forminator API Docs

1. Forminator API Docs

Written by Ash | Last updated: April 8, 2019
General
To initialize the API
/library/class-api.php
To retrieve all or specific forms
/library/class-api.php
To retrieve a form
/library/class-api.php
To delete a form
/library/class-api.php
To delete all or specific forms
/library/class-api.php
To add a form
/library/class-api.php
To update a form
/library/class-api.php
To retrieve all polls
/library/class-api.php
To retrieve a poll
/library/class-api.php
To delete a poll
/library/class-api.php
To delete specific polls
/library/class-api.php
To add a poll
/library/class-api.php
To update a poll
/library/class-api.php
To retrieve all quizzes
/library/class-api.php
To retrieve a quiz
/library/class-api.php
To delete a quiz
/library/class-api.php
To delete specific quizzes
/library/class-api.php
To add a quiz
/library/class-api.php
To update a quiz
/library/class-api.php
To get all fields of a given form
/library/class-api.php
To get a field of a given form
/library/class-api.php
Move a field to a new position in a given form
/library/class-api.php
Delete a field of a given form
/library/class-api.php
To get all fields of a given form
/library/class-api.php
To get all fields of same type of a given form
/library/class-api.php
To get a field of a given form by element ID
/library/class-api.php
To update a field of a given form by element ID
/library/class-api.php
To update a field of a given form by element ID
/library/class-api.php
To update a setting element of a given form
/library/class-api.php
To update setting elements of a given form
/library/class-api.php
To delete a field of a given form
/library/class-api.php
To delete multiple fields of a given form
/library/class-api.php
To get all entries of a given form
/library/class-api.php
To get one entry of a given form
/library/class-api.php
To move a field from a position to new postion
/library/class-api.php
To delete an entry for a form
/library/class-api.php
To delete an entry for a form
/library/class-api.php
The total number of entries
/library/class-api.php
Add an entry to a form
/library/class-api.php
Update an entry for a form
/library/class-api.php
Add multiple entries to a form
/library/class-api.php
Add an entry to a poll
/library/class-api.php
Add multiple entries to a poll
/library/class-api.php
Update an entry to a poll
/library/class-api.php
Add an entry to a quiz
/library/class-api.php
Add multiple entries to a quiz
/library/class-api.php
The element properties of the settings
/library/class-api.php

1.1 Method: initialize()

Copy chapter anchor to clipboard

Description

This method is used for initializing the Forminator API. Though you don’t need to initialize when you use the API methods. Every methods in the API checks if this is initialized and if it is not, then it will initialize itself.

Usage

Forminator_API::initialize();

Parameters

It doesn’t have any parameters.

Return

There is nothing to return.

Example

Forminator_API::initialize();

1.2 Method: get_forms()

Copy chapter anchor to clipboard

Description

This method is used to get all the form objects. Those objects are instances of Forminator_Base_Form_Model class.

Usage

Forminator_API::get_forms();

  • If you don’t pass any parameter, then it will return all the form objects as an array.
  • To get specific forms, you have two ways:
    • Make an array of those form IDs and pass the array as parameter $form_ids
    • Pass all the IDs of the forms as separate parameters in that method

Parameters

$form_ids
String | Array
The array of form IDs

Example

Return

An array of form objects.

1.3 Method: get_form()

Copy chapter anchor to clipboard

Description

This method will return the form object of the given form ID, it is an instance of Forminator_Base_Form_Model class.

Usage

Forminator_API::get_form( $form_id );

Parameters

$form_id
INT
The ID of the form

Example

Return

The form object.

1.4 Method: delete_form()

Copy chapter anchor to clipboard

Description

This method is used to delete a form from your list.

Usage

Forminator_API::delete_form( $form_id );

Parameters

$form_id
INT
The ID of the form

Example

$form = Forminator_API::delete_form( $form_id );

Return

TRUE => If the form is deleted
WP_ERROR => If there is an error to delete the form

1.5 Method: delete_forms()

Copy chapter anchor to clipboard

Description

This method is used to delete all the form objects of the given IDs.

Usage

Forminator_API::delete_forms( $form_ids );

  • Forminator_API::delete_forms( $form_ids );
    • Make an array of those form IDs and pass the array as parameter $form_ids
    • Pass all the IDs of the forms as separate parameters in that method

Parameters

$form_id
String | Array
The array of the form IDs

Example

Return

TRUE => If the form is deleted
WP_ERROR => If there is an error to delete the form

1.6 Method: add_form()

Copy chapter anchor to clipboard

Description

This method is used to create a new form.

Usage

Forminator_API::add_form( ‘Form Test 3’, $wrappers, $settings );

Parameters

$name
String
The name of the form
$wrappers
Array
The array of elements array with related parameters
$settings
Array
The array of settings options

Example

Some notes:

  • Wrapper ID should be unique and random numbers. The pattern is wrapper-xxxxxxxxxxx-yyyy where you can’t change wrapper, xxxxxxxxxxxx is a unique random number and yyyy is another unique and random number.
  • element_id should be unique too. So, if you have two text field, one should be text-1 and another one is text-2 and so on.
  • type is the field type, it could be name, email, text, phone etc
  • cols should be 12 if you want a field in one column. To keep two fields in one column, give the value 6 for cols parameter
  • $settings is an array of different settings element

Return

ID => ID of the create form
WP_Error => The error if the form is not created

1.7 Method: update_form()

Copy chapter anchor to clipboard

Description

This method is used to update a form.

Usage

Forminator_API::update_form( 352, $wrappers, $settings );

Parameters

$id
INT
The ID of the form
$wrappers
Array
The array of elements array with related parameters
$settings
Array
The array of settings options

Example

Return

ID => ID of the updated form
WP_Error => The error if the form is not created

1.8 Method: get_polls()

Copy chapter anchor to clipboard

Description

This method is used to get all the poll objects. Those objects are instances of Forminator_Base_Form_Model class.

Usage

Forminator_API::get_polls();

Parameters

There is no parameter

Example

Forminator_API::get_polls();

Return

An array of poll object

1.9 Method: get_poll()

Copy chapter anchor to clipboard

Description

This method will return the poll object of the given poll ID; it is an instance of Forminator_Base_Form_Model class.

Usage

Forminator_API::get_poll( $poll_id );

Parameters

$poll_id
INT
The ID of the poll

Example

Return

The poll object.

1.10 Method: delete_poll()

Copy chapter anchor to clipboard

Description

This method is used to delete a poll from your list.

Usage

Forminator_API::delete_poll( $poll_id );
Here $poll_id is the ID of the poll that you want to delete.

Parameters

$poll_id
INT
The ID of the poll

Example

Return

TRUE => If the poll is deleted
WP_ERROR => If there is an error to delete the poll

1.11 Method: delete_polls()

Copy chapter anchor to clipboard

Description

This method is used to delete the polls of the given IDs.

Usage

Forminator_API::delete_polls( $poll_ids );
Here $poll_ids is an array of poll IDs.

Parameters

$poll_ids
Array
The array of poll IDs

Example

Return

TRUE => If the poll is deleted
WP_ERROR => If there is an error to delete the poll

1.12 Method: add_poll()

Copy chapter anchor to clipboard

Description

This method is used to create a new poll.

Usage

Forminator_API::add_poll ( “Does it work?”, $answers, $settings );

Parameters

$name
String
The name of the form
$answers
Array
The array of answers with related parameters
$settings
Array
The array of settings options

Example

Return

ID => ID of the create form
WP_Error => The error if the form is not created

1.13 Method: update_poll()

Copy chapter anchor to clipboard

Description

This method is used to update a poll.

Usage

Forminator_API::update_poll ( 352, $answers, $settings );

Parameters

$id
INT
The ID of the form
$answers
Array
The array of answers with related parameters
$settings
Array
The array of settings options

Example

Return

ID => ID of the updated form
WP_Error => The error if the form is not updated

1.14 Method: get_quizzes()

Copy chapter anchor to clipboard

Description

This method is used to get all the quiz objects. Those objects are instances of Forminator_Base_Form_Model class.

Usage

Forminator_API::get_quizzes();

  • If you don’t pass any parameter, then it will return all the quiz objects as an array.
  • To get specific quizzes, you have two ways:
    • Make an array of those quiz IDs and pass the array as parameter $quiz_ids
    • Pass all the IDs of the forms as separate parameters in that method

Parameters

$quiz_ids
String | Array
The array of quiz IDs

Example

Return

An array of quiz objects.

1.15 Method: get_quiz()

Copy chapter anchor to clipboard

Description

This method will return the form object of the given quiz ID, it is an instance of Forminator_Base_Form_Model class.

Usage

Forminator_API::get_quiz( $quiz_id );

Here $quiz_id is the ID of the form that you want to fetch as an object.

Parameters

$quiz_id
INT
The ID of the quiz

Example

$quiz_id = 35;
$form = Forminator_API::get_ quiz( $quiz_id );

Return

The quiz object.

1.16 Method: delete_quiz()

Copy chapter anchor to clipboard

Description

This method is used to delete a quiz from your list.

Usage

Forminator_API::delete_quiz( $quiz_id );

Here $quiz_id is the ID of the quiz that you want to delete.

Parameters

$quiz_id
INT
The ID of the quiz

Example

$form = Forminator_API::delete_quiz( $quiz_id );

Return

TRUE => If the quiz is deleted
WP_ERROR => If there is an error to delete the quiz

1.17 Method: delete_quizzes()

Copy chapter anchor to clipboard

Description

This method is used to delete all the quiz objects of the given IDs.

Usage

Forminator_API::delete_quizzes( $quiz_ids );

  • To delete specific quizzes, you have two ways:
    • Make an array of those quiz IDs and pass the array as parameter $quiz_ids
    • Pass all the IDs of the quizzes as separate parameters in that method

Parameters

$quiz_ids
String | Array
The array of quiz IDs

Example

Return

TRUE => If the quiz is deleted
WP_ERROR => If there is an error to delete the quiz

1.18 Method: add_quiz()

Copy chapter anchor to clipboard

Description

This method is used to create a new quiz.

Usage

Forminator_API::add_quiz ( “Does it work?”, “knowledge”, $questions, $results, $settings );

Parameters

$name
STRING
The name of the quiz
$type
STRING
The type of the quiz
$questions
ARRAY
The array of question options
$result
ARRAY
The array of result options
$settings
ARRAY
The array of settings options

Example

Return

ID => ID of the create quiz
WP_Error => The error if the quiz is not created

1.19 Method: update_quiz()

Copy chapter anchor to clipboard

Description

This method is used to update a quiz.

Usage

Forminator_API::update_quiz( 352, $questions, $results, $settings );

Parameters

$id
INT
The ID of the quiz
$questions
Array
The array of question options
$result
Array
The array of result options
$settings
Array
The array of settings options

Example

Return

ID => ID of the updated quiz
WP_Error => The error if the quiz is not updated

1.20 Method: get_form_wrappers()

Copy chapter anchor to clipboard

Description

This method is used to retrieve all fields of a form.

Usage

Forminator_API::get_form_wrappers( 352 );

Parameters

$id
INT
The ID of the form

Example

Return

ARRAY => Array of fields of a form
WP_Error => The error if the fields are not retrieved

1.21 Method: get_form_wrapper()

Copy chapter anchor to clipboard

Description

This method is used to retrieve a field of a form.

Usage

Forminator_API::get_form_wrapper( 352, ‘wrapper-1511347712118-1739’ );

Parameters

$id
INT
The ID of the form
$form_id
STRING
The ID of the field wrapper

Example

Return

ARRAY => Array of the field properties of a form
WP_Error => The error if the field is not retrieved

1.22 Method: move_form_wrapper()

Copy chapter anchor to clipboard

Description

To move position of a form field

Usage

Forminator_API::move_form_wrapper( 352, ‘wrapper-1511347712118-1739’, 3 );

Parameters

$id
INT
The ID of the form
$form_id
STRING
The ID of the field wrapper
$new_position
INT
The new position of the field, starts with zero

Example

Return

ARRAY => Array of the field properties of a form
WP_Error => The error if the field is not retrieved

1.23 Method: delete_form_wrapper()

Copy chapter anchor to clipboard

Description

To delete a field of a form

Usage

Forminator_API::delete_form_wrapper( 352, ‘wrapper-1511347712118-1739’ );

Parameters

$form_id
STRING
The ID of the field wrapper
$id
INT
The ID of the form

Example

Return

TRUE => If the form is deleted
WP_Error => The error if the field is not deleted

1.24 Method: get_form_fields()

Copy chapter anchor to clipboard

Description

This method is used to retrieve all fields of a form.

Usage

Forminator_API::get_form_fields( 352 );

Parameters

$id
INT
The ID of the form

Example

Return

ARRAY => Array of fields of a form
WP_Error => The error if the fields are not retrieved

1.25 Method: get_form_fields_by_type()

Copy chapter anchor to clipboard

Description

This method is used to retrieve all fields from the same type in a form.

Usage

Forminator_API::get_form_fields_by_type( 352, ’email’ );

Parameters

$id
INT
The ID of the form
$type
STRING
The type of the field

Example

Return

ARRAY => Array of the fields of a form
WP_Error => The error if the fields are not retrieved

1.26 Method: get_form_field()

Copy chapter anchor to clipboard

Description

This method is used to retrieve a fields from a form by element ID

Usage

Forminator_API::get_form_field( 7, ’email-2′ );

Parameters

$form_id
INT
The ID of the form
$id
STRING
The elemend ID of the field
$to_array
BINARY
TRUE if the result is supposed to be an array, FALSE for object

Example

Return

ARRAY => Array or object of the fields of a form
WP_Error => The error if the fields are not retrieved

1.27 Method: update_form_field()

Copy chapter anchor to clipboard

Description

This method is used to update a fields from a form by element ID

Usage

Forminator_API::update_form_field( 7, ’email-2′, $data );

Parameters

$form_id
INT
The ID of the form
$id
STRING
The elemend ID of the field
$data
ARRAY
The array of the field element

Example

Return

There is nothing to return

1.28 Method: add_form_field()

Copy chapter anchor to clipboard

Description

This method is used to add a field from a form by element ID

Usage

Forminator_API::add_form_field( $form_id, $type, $data );

Parameters

$form_id
INT
The ID of the form
$type
STRING
The type of the field
$data
ARRAY
The array of the field element

Example

Return

There is nothing to return

1.29 Method: update_form_setting()

Copy chapter anchor to clipboard

Description

This method is used to update a setting element of a form

Usage

Forminator_API::update_form_setting( $form_id, $setting, $value );

Parameters

$form_id
INT
The ID of the form
$setting
STRING
The name of the setting
$value
STRING | ARRAY
The value of the setting

Example

Return

The ID of the form

1.30 Method: update_form_settings()

Copy chapter anchor to clipboard

Description

This method is used to update a setting element of a form

Usage

Forminator_API::update_form_setting( $form_id, $settings );

Parameters

$form_id
INT
The ID of the form
$settings
ARRAY
The element array

Example

Return

The ID of the form

1.31 Method: delete_form_field()

Copy chapter anchor to clipboard

Description

This method is used to delete a field of a form

Usage

Forminator_API::delete_form_field( $form_id, $id )

Parameters

$form_id
INT
The ID of the form
$id
STRING
The field ID

Example

Return

The ID of the deleted field

1.32 Method: delete_form_fields()

Copy chapter anchor to clipboard

Description

This method is used to delete multiple fields of a form

Usage

Forminator_API::delete_form_fields( $form_id, $field_ids )

Parameters

$form_id
INT
The ID of the form
$field_ids
ARRAY
The array of field IDs

Example

Return

TRUE => If deleted
WP_ERROR => If it fails

1.33 Method: get_entries()

Copy chapter anchor to clipboard

Description

This method is used to get all entries of a form

Usage

Forminator_API::get_entries( $form_id );

Parameters

$form_id
INT
The ID of the form

Example

Return

Forminator_Form_Entry_Model => If success
WP_ERROR => If it fails

1.34 Method: get_entry()

Copy chapter anchor to clipboard

Description

This method is used to get one entry of a form

Usage

Forminator_API::get_entry( $form_id, $entry_id );

Parameters

$form_id
INT
The ID of the form
$entry_id
INT
The ID of the entry

Example

Return

Forminator_Form_Entry_Model => If success
WP_ERROR => If it fails

1.35 Method: move_form_field()

Copy chapter anchor to clipboard

Description

This method is used to move a field from a position to a new position in a form

Usage

Forminator_API::move_form_field( $form_id, $id, $new_position, $new_wrapper_id );

Parameters

$form_id
INT
The ID of the form
$id
STRING
The ID of the field
$new_position
INT
The new position of the field
$new_wrapper_id
STRING
(optional) You can set a wrapper ID which identifies in which wrapper should the field moved

Example

Return

The field object => If success
Field ID => If it fails

1.36 Method: delete_entry()

Copy chapter anchor to clipboard

Description

This method is used to delete an entry from the entry list

Usage

Forminator_API::delete_entry( $form_id, $entry_id );

Parameters

$form_id
INT
The ID of the form
$entry_id
INT
The ID of the entry

Example

Return

True => If success
WP_Error => If it fails

1.37 Method: delete_entries()

Copy chapter anchor to clipboard

Description

This method is used to delete an entry from the entry list

Usage

Forminator_API::delete_entries( $form_id, $entry_ids );

Parameters

$form_id
INT
The ID of the form
$entry_ids
ARRAY
The array of IDs of the entries

Example

Return

True => If success
WP_Error => If it fails

1.38 Method: count_entries()

Copy chapter anchor to clipboard

Description

This method is used to get the number of total entries

Usage

Forminator_API::count_entries( $form_id )

Parameters

$form_id
INT
The ID of the form

Example

Return

INT => If success
WP_Error => If it fails

1.39 Method: add_form_entry()

Copy chapter anchor to clipboard

Description

This method is used to add an entry to a form

Usage

Forminator_API::add_form_entry( $form_id, $entry_meta );

Parameters

$form_id
INT
The ID of the form
$entry_meta
ARRAY
The array of entries

Example

Return

INT => Entry ID

1.40 Method: update_form_entry()

Copy chapter anchor to clipboard

Description

This method is used to update an entry to a form

Usage

Forminator_API::update_form_entry( $form_id, $entry_id, $entry_meta );

Parameters

$form_id
INT
The ID of the form
$entry_id
STRING
The ID of the entry
$entry_metas
ARRAY
The array of entries

Example

Return

INT => Entry ID

1.41 Method: add_form_entries()

Copy chapter anchor to clipboard

Description

This method is used to add multiple entries to a form

Usage

Forminator_API::add_form_entries( $form_id, $entry_metas );

Parameters

$form_id
INT
The ID of the form
$entry_metas
ARRAY
The array of array of entries

Example

Return

INT => Entry ID

1.42 Method: add_poll_entry()

Copy chapter anchor to clipboard

Description

This method is used to add an entry to a poll

Usage

Forminator_API::add_poll_entry( $poll_id, $entry_meta );

Parameters

$poll_id
INT
The ID of the form
$entry_metas
ARRAY
The array of entries

Example

Return

INT => Entry ID

1.43 Method: add_poll_entries()

Copy chapter anchor to clipboard

Description

This method is used to add multiple entries to a poll

Usage

Forminator_API::add_poll_entries( $poll_id, $entry_metas );

Parameters

$poll_id
INT
The ID of the poll
$entry_metas
ARRAY
The array of array of entries

Example

Return

INT => Entry ID

1.44 Method: update_poll_entry()

Copy chapter anchor to clipboard

Description

This method is used to update an entry to a form

Usage

Forminator_API::update_poll_entry( $poll_id, $entry_id, $entry_meta );

Parameters

$poll_id
INT
The ID of the poll
$entry_id
INT
The ID of the entry
$entry_meta
ARRAY
The array of entries

Example

Return

INT => Entry ID

1.45 Method: add_quiz_entry()

Copy chapter anchor to clipboard

Description

This method is used to update an entry to a form

Usage

Forminator_API::add_quiz_entry( $quiz_id, $entry_meta );

Parameters

$quiz_id
INT
The ID of the quiz
$entry_meta
ARRAY
The array of entries

Example

Return

INT => Entry ID

1.46 Method: add_quiz_entries()

Copy chapter anchor to clipboard

Description

This method is used to update an entry to a form

Usage

Forminator_API::add_quiz_entries( $quiz_id, $entry_metas );

Parameters

$quiz_id
INT
The ID of the quiz
$entry_metas
ARRAY
The array of array of entries

Example

Return

INT => Entry ID

1.47 Settings Element

Copy chapter anchor to clipboard

Here are some settings element that you can use in the settings array: