Validating Forms with REST API v2

Introduction

The form submissions/validation endpoint was added in Gravity Forms 2.6.3.2, it is used to validate the form input values.

If the form passes validation the configured anti-spam checks will also be performed.

The following features and processes are NOT supported:

  • Saving progress for the save and continue feature
  • Payment add-on validation
  • Saving the entry
  • Add-on feeds
  • Notifications
  • Confirmations
  • Most of the filters and action hooks triggered by a regular form submission. Note: validation filters such as gform_pre_validation, gform_field_validation, and gform_validation will be triggered.

If you require any of the above you should use the form submissions endpoint instead.

Authentication

See REST API v2 Authentication.

Gravity Forms capabilities are not required to use this endpoint.

Method

This endpoint only accepts POST requests.

Path

/gf/v2/forms/[FORM_ID]/submissions/validation

or (since v2.6.3.3)

/gf/v2/forms/[FORM_ID]/submissions?_validate_only=1

Content-Type

This endpoint supports the application/json, application/x-www-form-urlencoded, and multipart/form-data content types.

File uploads for single file upload type fields are only supported when using multipart/form-data.

Required Properties

The request body should contain an associative array of values to be validated using the field input names (e.g. input_1) as the keys.

The expected input names are identical to the input names found in the form markup. If you have any doubts about the name of an input, use your browsers developer tools to inspect the inputs via the form preview page.

Optional Properties

The request body can also include the following properties.

KeyTypeDescription
field_valuesarrayAn array of dynamic population parameter keys with their corresponding values used to populate the fields.
target_pageintegerDefault is 0.
For multi-page forms; indicates which page would be loaded next if the current page passes validation.
source_pageintegerDefault is 1.
For multi-page forms; indicates which page was active when the values were submitted for validation.

Response [json]

The response will contain a JSON object which contains the following:

KeyTypeDescription
is_validboolThe form validation result.
validation_messagesarray|objectField IDs as keys to their validation error messages.
page_numberintegerFor multi-page forms.
The page that should be displayed.
source_page_numberintegerFor multi-page forms.
The page that was submitted.
is_spamboolOnly present when is_valid is true.
Indicates if the submission has been identified as spam.

Usage Examples

application/json

cURL Request

curl --location --request POST 'https://example.com/wp-json/gf/v2/forms/1/submissions/validation' \

--header 'Content-Type: application/json' \
--data-raw '{
    "input_1": "value",
    "input_2": "another value"
}'

Response

{
    "is_valid": true,
    "validation_messages": [],
    "page_number": 0,
    "source_page_number": 1,
    "is_spam": false
}

multipart/form-data

cURL Request

curl --location --request POST 'https://example.com/wp-json/gf/v2/forms/1/submissions/validation' \

--form 'input_1="value"' \
--form 'input_3=@"/path/to/file.jpg"'

Response

{
    "is_valid": false,
    "validation_messages": {
        "3": "The uploaded file type is not allowed. Must be one of the following: pdf"
    },
    "page_number": 1,
    "source_page_number": 1
}