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: July 12, 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 add a quiz
/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 Settings Element

Link to chapter 20

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