Submitted value () does not match expected value ($XXX) [RESOLVED]

Hi all!

I am getting this error on my WP site as of today. I am always on the most recent version and I have read several posts about this. The only thing that applies to me is one conditional field. BUT..I have removed the conditional format and there is still an issue.

My form is very very simple.

Please assist as this is keeping customers from ordering.

Order form: Order - The Squeal Killer

Thank you!

Hi Jason,

I checked your order form. The problem is not the conditional logic.

Your theme adds a <br /> tag inside the form HTML (WordPress “wpautop” runs on the form after it is rendered). In the Total field, this <br /> sits between the total text and the hidden input that stores the total. So the script writes the total into the <br /> and the real input stays empty. When the form is submitted, Gravity Forms sees an empty total and shows “Submitted value () does not match expected value”.

Easiest fix:

  1. Go to Forms > your Order form > Settings.
  2. In “Form Layout”, turn off “Enable legacy markup”.
  3. Save and test an order.

If you want to keep legacy markup, add this as a mu-plugin (wp-content/mu-plugins/gf-total-fix.php):

  add_filter( 'gform_field_content', function ( $content, $field ) {
      if ( $field->type === 'total' ) {
          $content = preg_replace( '#</span>\s+<input#', '</span><input', $content );
      }
      return $content;
  }, 10, 2 );

Also, your theme loads a very old jQuery (1.10.2) from Google instead of the WordPress one. It is not the cause here, but it can break other things, so please ask your theme developer to remove that.

Let me know if it works.

Hey Faisal!

Thank you for the suggestions.

I removed the legacy markup. However, it changed a whole hosts of things like alignment, loss of graphics.

So…not good and now I don’t see that as an option i.e. to put back Legacy markup.

Please explain what you mean by add a mu-plugin. Where? How?

Thanks so much sir!

Anyone else? Right now my site is messed up and I don’t have a way to fix it because the legacy option is gone after I turned it off.

Thanks

Hi Jason,

Sorry about the layout change. Once legacy markup is turned off, Gravity Forms hides that setting, so you can’t turn it back on from the form settings. But we can turn it back on with a small code file, and the same file also fixes the Total error.

A “mu-plugin” (must-use plugin) is a PHP file that WordPress loads automatically. You don’t need to activate it.

How to add it:

  1. Open your site files with your hosting File Manager (cPanel, etc.) or FTP.
  2. Go to the wp-content folder.
  3. If there is no mu-plugins folder inside it, create one. The name must be exactly mu-plugins.
  4. Inside mu-plugins, create a new file named gf-order-form-fix.php.
  5. Paste this code into the file and save it:
<?php
/**
 * Plugin Name: GF Order Form Fix
 */

// Turn legacy markup back on for form ID 1 (your Order form).
add_filter( 'gform_enable_legacy_markup_1', '__return_true' );

// Fix the empty Total value caused by the extra <br /> tag.
add_filter( 'gform_field_content', function ( $content, $field ) {
	if ( $field->type === 'total' ) {
		$content = preg_replace( '#</span>\s+<input#', '</span><input', $content );
	}
	return $content;
}, 10, 2 );
  1. If you use a cache plugin or server cache, clear it.
  2. Open the order page and test an order.

Your form should look like before, and the Total should now submit correctly.

If you can’t access the files, you can install the free “Code Snippets” plugin and add the same code there (without the first <?php line), set to “Run everywhere”.

Let me know how it goes.

Man… you are a lifesaver. THANK YOU!!

Worked 100% and the site/order form is back to 100%.

A pint on me if you are ever in my area :slight_smile:

Hi Jason,

You’re very welcome! I’m glad the fix worked and that your site and order form are back to normal. :slight_smile:

If you’d like to buy me a coffee, you can do so here: https://buymeacoffee.com/faisalahammad

Thanks again for the kind words! :handshake:

FYI, legacy markup will be removed in version 4.0, which is currently in development for release early next year, so I recommend finding the time to clone your site to a staging or development site and working on resolving any CSS issues with the modern markup.