This page may contain affiliate links. Please read my disclaimer for more information.

How to Submit a Form Without Values – Gravity Forms

  |  by Chris Eggleston

Problem

Gravity Forms has a validation feature that prevents you from being able to submit a form if all fields are empty, even if they are not required. This help doc will show you how to bypass validation.

The specific error is: At least one field must be filled out.

I am not sure why you’d want someone to be able to submit a form without populating any of the fields, but that was a recent request I received from two Gravity Forms users over the past couple of weeks.

Solution

I have two possible solutions for this request that will enable you to bypass validation.

One option uses a code snippet, and the other uses a hidden field (no code).

No Code

This solution uses a hidden single text field with a default value. You can even use conditional logic to ensure that the hidden field is only evaluated when all visible fields are empty.

  1. Add a single line text field to the form
  2. Change the visibility to hidden
  3. Add Default Value

If you want to use conditional logic, here is an example of how you’d set that up.

Code

This solution only requires adding the code snippet below to your site. It can be added to your themes functions.php file or a code snippet plugin.

You need to make only one modification: replace the 1 in gform_validation_1 on the first line of the code with your form ID number.

/**
 * GravityRanger // Gravity Forms // Bypass empty field validation 'At least one field must
 * be filled out'
 * https://gravityranger.com/
 *
 * This snippet will allow you to bypass validation and submit an empty form.
 * Replace the 1 in gform_validation_1 with your forms ID to apply to a specific form. Or
 * remove _1 to apply to all forms.
 * NOTE: This will bypass validation even if fields are marked as required.
 * 
 */


add_filter( 'gform_validation_1', 'custom_gform_validation' );
function custom_gform_validation( $validation_result ) {
    // Get the form object from the validation result
    $form = $validation_result['form'];

    // Create a flag to track if any field has been filled
    $is_filled = false;

    // Loop through the form fields to check if any field is populated
    foreach ( $form['fields'] as $field ) {
        $field_value = rgpost( 'input_' . $field->id );
        if ( !empty( $field_value ) ) {
            $is_filled = true;
            break;
        }
    }

    // If no field is filled, set the validation result to true (allow empty form submission)
    if ( !$is_filled ) {
        $validation_result['is_valid'] = true;
    }

    return $validation_result;
}

This code will bypass validation for required and non-required fields.

NEED MORE HELP?

If you still need help, feel free to use the comments or chat options below.

If you have an active Gravity Forms license, you can also open a support ticket here.

Photo of author
About the Author
Chris Eggleston
I’m not just a Gravity Forms enthusiast; I’m a dedicated father and loving husband. As the owner of WP Mantis & Marketing Draft, I’m on a mission to simplify the WordPress experience for site owners. I try to bring a unique perspective to the Gravity Forms community.
Gravity Wiz Add-Ons

Advertisement

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments