Hey, WordPress web developer :)

Check out WPMU DEV

Skip to Main Content
Docs / / Forminator API Docs

5. Forminator API Docs

Written by Ash | Last updated: August 15, 2018
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

5.1 Method: initialize()

Link to chapter 1

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();

5.2 Method: get_forms()

Link to chapter 2

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.

5.3 Method: get_form()

Link to chapter 3

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.

5.4 Method: delete_form()

Link to chapter 4

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

5.5 Method: delete_forms()

Link to chapter 5

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

5.6 Method: add_form()

Link to chapter 6

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

5.7 Method: update_form()

Link to chapter 7

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

5.8 Method: get_polls()

Link to chapter 8

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

5.9 Method: get_poll()

Link to chapter 9

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.

5.10 Method: delete_poll()

Link to chapter 10

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

5.11 Method: delete_polls()

Link to chapter 11

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

5.12 Method: add_poll()

Link to chapter 12

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

5.13 Method: update_poll()

Link to chapter 13

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

5.14 Method: get_quizzes()

Link to chapter 14

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.

5.15 Method: get_quiz()

Link to chapter 15

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.

5.16 Method: delete_quiz()

Link to chapter 16

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

5.17 Method: delete_quizzes()

Link to chapter 17

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

5.18 Method: add_quiz()

Link to chapter 18

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

5.19 Method: update_quiz()

Link to chapter 19

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

5.20 Method: get_form_wrappers()

Link to chapter 20

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

5.21 Method: get_form_wrapper()

Link to chapter 21

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

5.22 Method: move_form_wrapper()

Link to chapter 22

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

5.23 Method: delete_form_wrapper()

Link to chapter 23

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

5.24 Method: get_form_fields()

Link to chapter 24

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

5.25 Method: get_form_fields_by_type()

Link to chapter 25

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

5.26 Method: get_form_field()

Link to chapter 26

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

5.27 Method: update_form_field()

Link to chapter 27

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

5.28 Method: add_form_field()

Link to chapter 28

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

5.29 Method: update_form_setting()

Link to chapter 29

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

5.30 Method: update_form_settings()

Link to chapter 30

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

5.31 Method: delete_form_field()

Link to chapter 31

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

5.32 Method: delete_form_fields()

Link to chapter 32

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

5.33 Method: get_entries()

Link to chapter 33

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

5.34 Method: get_entry()

Link to chapter 34

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

5.35 Method: move_form_field()

Link to chapter 35

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

5.36 Method: delete_entry()

Link to chapter 36

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

5.37 Method: delete_entries()

Link to chapter 37

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

5.38 Method: count_entries()

Link to chapter 38

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

5.39 Method: add_form_entry()

Link to chapter 39

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

5.40 Method: update_form_entry()

Link to chapter 40

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

5.41 Method: add_form_entries()

Link to chapter 41

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

5.42 Method: add_poll_entry()

Link to chapter 42

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

5.43 Method: add_poll_entries()

Link to chapter 43

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

5.44 Method: update_poll_entry()

Link to chapter 44

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

5.45 Method: add_quiz_entry()

Link to chapter 45

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

5.46 Method: add_quiz_entries()

Link to chapter 46

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

5.47 Settings Element

Link to chapter 47

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