In this article, we will show you how to do things such as import, export, update, delete, and even create forms using the CLI Add-On for Gravity Forms.
Pre-Requisites
Creating Forms
wp gf form create
Examples
- Creates a new form with just a title and description.
wp gf form create 'My Form Title' 'Description Here'
Parameters
Argument | Description |
---|---|
<title> | The title of the new form. Overrides the title defined in the optional JSON. |
[<description>] | The description of the new form. Overrides the description defined in the optional JSON. |
[--form-json=<value>] | The JSON formatted form. |
[--porcelain] | If used, outputs just the created form ID instead of the standard success message. |
Deleting Forms
wp gf form delete
Examples
- Move form 5 to the trash.
wp gf form delete 5
- Permanently delete form 5.
wp gf form delete 5 --force
Parameters
Argument | Description |
---|---|
<form-id>... | One or more IDs of forms to be deleted. |
[--force] | Skips the trash and permanently deletes the form. |
Duplicating Forms
wp gf form duplicate
Examples
- Creates a duplicate copy of form 5.
wp gf form duplicate 5
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form to be duplicated. |
[--porcelain] | If used, outputs just the duplicate form ID instead of the standard success message. |
Editing Forms
wp gf form edit
Examples
- Launch the editor for form 5.
wp gf form edit 5
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form to be edited. |
Exporting Forms
wp gf form export
Examples
- Exports all forms to the current working directory.
wp gf form export
- Exports form 5 to a specific location.
wp gf form export 5 --dir=/my/custom/path
- Exports form 5 using a custom filename.
wp gf form export 5 --filename=testing.json
Parameters
Argument | Description |
---|---|
[<form-id>] | The ID of the form to export. If not set, exports all forms. |
[--dir='value'] | The path to the location that the export should be stored. Default: current working directory. |
[--filename='value'] | The filename for the form to export. Defaults to the current date. |
[--porcelain] | Overrides the standard success message with just the export file path. |
Listing Forms
wp gf form list
Examples
- Get a JSON formatted list of active forms sorted by id.
wp gf form list --active --sort_column=id --format=json
Parameters
Argument | Description |
---|---|
[--active] | List active forms. Default: true. |
[--trash] | List forms in trash. Default: false. |
[--sort-column=<value>] | The column to sort the list by. Accepted values: id, title, date_created, is_active, and is_trash. Default: id. |
[--sort-dir=<value>] | The direction to use when sorting. Accepted values: ASC or DESC. Default: ASC. |
[--format=<value>] | Defines the format in which the forms will be listed. Accepted values: table, csv, json, and count. Default: table. |
Getting Forms
wp gf form get
Examples
- Gets the JSON for form 5.
wp gf form get 5
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form to get. |
Importing Forms
wp gf form import
Examples
- Imports one or more forms from the supplied .json file.
wp gf form import /path/to/my/file.json
Parameters
Argument | Description |
---|---|
<json-path> | The path to a file containing the JSON formatted form(s) to be imported. |
Updating Forms
wp gf form update
Note: This command replaces the existing form object. Always provide a complete and valid JSON form structure. Supplying a partial form object may corrupt the form or result in data loss.
Examples
- Updates form 5 using the supplied JSON string.
wp gf form update 5 --form-json='{snip}'
- Updates form 5 using the supplied .json file.
wp gf form update 5 --file='/path/to/my/file.json'
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form to update. |
[--form-json=<value>] | The JSON formatted form. |
[--file=<value>] | The path to a file containing the JSON formatted form. |
How To Update A Form
- Export a form using WP-CLI: wp gf form export 5 –path=./form-5.json
- Edit the file (form-5.json) to change any property
You can set a form as active/inactive updating the is_active property to true or false. - Apply the update using WP-CLI: wp gf form update 5 –file=./form-5.json
Form Properties Settings Reference
Note: This reference lists top-level properties only. It is not exhaustive and does not include field-level settings.
Property | Type | Description |
---|---|---|
id | integer | 123 |
title | string | “Subscribe” |
description | string | “” |
labelPlacement | string | “top_label” |
fields | array | 2 field objects (Name, Email A) |
button | object | {“type”:”text”,”text”:”Submit”,…} |
descriptionPlacement | string | “below” |
version | string | “2.9.8” |
markupVersion | integer | 2 |
nextFieldId | integer | 3 |
is_active | boolean | true |
useCurrentUserAsAuthor | boolean | true |
postContentTemplateEnabled | boolean | false |
postTitleTemplateEnabled | boolean | false |
postTitleTemplate | string | “” |
postContentTemplate | string | “” |
lastPageButton | null | null |
pagination | null | null |
firstPageCssClass | null | null |
validationPlacement | string | “below” |
subLabelPlacement | string | “below” |
requiredIndicator | string | “text” |
customRequiredIndicator | string | “(Required)” |
cssClass | string | “” |
saveButtonText | string | “Save & Continue” |
limitEntries | boolean | false |
limitEntriesCount | string | “” |
limitEntriesPeriod | string | “” |
limitEntriesMessage | string | “” |
scheduleForm | boolean | false |
scheduleStart | string | “” |
scheduleEnd | string | “” |
schedulePendingMessage | string | “” |
scheduleMessage | string | “” |
requireLogin | boolean | false |
requireLoginMessage | string | “” |
enableHoneypot | boolean | true |
honeypotAction | string | “spam” |
validationSummary | boolean | false |
deprecated | string | “” |
saveEnabled | string | “” |
enableAnimation | boolean | false |
save | object | {“enabled”:false,”button”:{“type”:”link”,”text”:”Save & Continue”}} |
scheduleStartHour | string | “” |
scheduleStartMinute | string | “” |
scheduleStartAmpm | string | “” |
scheduleEndHour | string | “” |
scheduleEndMinute | string | “” |
scheduleEndAmpm | string | “” |
confirmations | array | 1 confirmation object (“Default Confirmation”) |
notifications | array | 1 notification object (“Admin Notification”) |