Creating Forms with the GFAPI

Introduction

The GFAPI::add_form(), GFAPI::add_forms(), and GFAPI::duplicate_form() methods are used to create forms.

Adding a single form

The GFAPI::add_form() method is used to add a single form.

Source Code

public static function add_form( $form_meta ) {}

This method is located in /includes/api.php.

Parameters

ParamTypeDescription
$form_metaarrayAn associative array containing the form settings, fields, notifications, confirmations, and other properties (e.g. add-on settings). See Form Object.

Returns

An integer, the form ID, or a WP_Error instance if an error occurs.

Usage Example

$result = GFAPI::add_form( $form_meta );

Adding multiple forms

The GFAPI::add_forms() method is used to add multiple forms.

Source Code

public static function add_forms( $forms ) {}

This method is located in /includes/api.php.

Parameters

ParamTypeDescription
$formsarrayAn array of associative arrays containing the form settings, fields, notifications, confirmations, and other properties (e.g. add-on settings). See Form Object.

Returns

An array of integers, the form IDs, or a WP_Error instance if an error occurs.

Usage Example

$result = GFAPI::add_forms( array( $form_1_meta, $form_2_meta ) );

Duplicating a form

The GFAPI::duplicate_form() method is used to add a single form by duplicating an existing form.

Source Code

public static function duplicate_form( $form_id ) {}

This method is located in /includes/api.php.

Parameters

ParamTypeDescription
$form_idintegerThe ID of an existing form to be duplicated.

Returns

An integer, the new form ID, or a WP_Error instance if an error occurs.

Usage Example

$result = GFAPI::duplicate_form( $form_id );