Allow Entry-less Submissions

Bypass Gravity Forms default validation that requires at least one field to be filled out to submit a form.

Note: An empty entry is still created with this snippet. If truly entry-less submissions become a popular request, we will revisit.

Code

Filename: gspc-entryless-submissions.php

<?php
/**
 * Gravity Shop // Product Configurator // Allow Entry-less Submissions
 * https://gravitywiz.com/documentation/gs-product-configurator/
 *
 * Bypass Gravity Forms default validation that requires at least one field to be filled out to submit a form.
 *
 * Note: An empty entry is still created with this snippet. If truly entry-less submissions become a popular request, we
 * will revisit.
 */
add_filter( 'gform_validation', function( $result ) {
	if ( rgpost( 'gspc_product_price' ) && ! $result['is_valid'] && $result['form']['fields'][0]['validation_message'] == esc_html__( 'At least one field must be filled out', 'gravityforms' ) ) {
		$result['is_valid'] = true;
		foreach ( $result['form']['fields'] as &$field ) {
			$field->failed_validation  = false;
			$field->validation_message = '';
		}
		add_filter( 'gform_abort_submission_with_confirmation', '__return_true' );
	}
	return $result;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.