When using the CLI Add-On for Gravity Forms, you are able to easily manage your forms fields using only the command line, via WP-CLI. In this article, we will show you how to do things such as update, delete, and even create form fields using WP-CLI.
Pre-Requisites
Creating Fields
wp gf field create
Examples
- Create a new text type field for form 1.
wp gf field create 1 text 'My Text Field'
- Create a new select field for form 1 from the supplied JSON.
wp gf field create 2 --field-json='{"type": "select", "label": "My Dropdown", "enableChoiceValue": true, "choices": [{"text": "Choice 1", "value":"one"}, {"text": "Choice 2", "value":"two"}]}'
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form to create a field in. |
<type> | The type of field to create. Examples: text, textarea, email. See the type properties of the field classes which extend GF_Field. |
[<label>] | The label to associate with the created field. |
[--field-json=<value>] | The JSON formatted field properties. |
[--porcelain] | Outputs just the created field ID. |
Deleting Fields
wp gf field delete
Examples
- Deletes field 2 from form 5.
wp gf field delete 5 2
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form that a field will be deleted from. |
<field-id> | The ID of the field to be deleted. |
Duplicating Fields
wp gf field duplicate
Examples
- Duplicates field 2 of form 5.
wp gf field duplicate 5 2
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form that a field will be duplicated in. |
<field-id> | The ID of the field to be duplicated. |
Editing Fields
wp gf field edit
Examples
- Launch the editor for field 2 of form 5.
wp gf field edit 5 2
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form that contains the field you want to edit. |
<field-id> | The ID of the field to be edited. |
Getting Fields
wp gf field get
Examples
- Gets the JSON for field 2 of form 5.
wp gf field get 5 2
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form that contains the field you want to view. |
<field-id> | The ID of the field you want to view. |
Listing Fields
wp gf field list
Examples
- Get a table formatted list of fields from form 5.
wp gf field list 5
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form that you want to list fields from. |
[--format=<value>] | Defines the format in which the fields will be listed. Accepted values: table, csv, json, yaml, and count. Default: table. |
Updating Fields
wp gf field update
Examples
- Updates field 2 of form 5 with the supplied JSON.
wp gf field update 5 2 --field-json='{"type": "text", "label": "My New Label", "defaultValue": "Just testing"}'
- Update the specified properties of form 2 field 5.
wp gf field update 5 2 --type=text --label='My New Label'
Parameters
Argument | Description |
---|---|
<form-id> | The ID of the form that contains the field that will be updated. |
<field-id> | The ID of the field you want to update. |
[--<property>=<value>] | The field property and value to be updated. |
[--field-json=<value>] | The JSON formatted field properties. |