Creating Entries with the GFAPI

Introduction

The GFAPI::add_entry() and GFAPI::add_entries() methods are used to add entries directly to the database.

These methods do not trigger form submission processes such as validation, add-on feeds, notifications, or confirmations; to trigger those processes see Submitting Forms with the GFAPI.

Adding a single entry

The GFAPI::add_entry() method is used to add a single entry.

Source Code

public static function add_entry( $entry ) {}

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

Parameters

ParamTypeDescription
$entryarraySee Entry Object.
If the id property is included it will be ignored.
The form_id property is required.
All other properties, meta, and field values are optional.

Returns

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

Usage Example

$result = GFAPI::add_entry( $entry );

Adding multiple entries

The GFAPI::add_entries() method is used to add multiple entries.

Source Code

public static function add_entries( $entries, $form_id = null ) {}

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

Parameters

ParamTypeDescription
$entriesarrayAn array containing one or more entry arrays.
See Entry Object.
If the id property is included it will be ignored.
The form_id property is required if the $form_id param is not specified.
All other properties, meta, and field values are optional.
$form_idnull|integerOptional.
The ID of the form the entries are to be added to.
If specified the form_id property included in the entry arrays will be ignored.

Returns

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

Usage Example

$result = GFAPI::add_entries( array( $entry_1, $entry_2 ) );