Jonah Coyote Design

Add Body Class on Gravity Forms Submisson

Introduction

You probably have all kinds of elements on a page that you don’t want to show when a Gravity Form is submitted. This helps convey to the user your confirmation you received their request, and any further or possible steps they can take. This post shows you simply how to add a body class to your HTML to then be able to hide any elements you want when a Gravity Form is successfully submitted.

The Solution

Add the following to your theme functions.php

/*-------------------------------------------------------------------------------
	Add Body Class on Gforms Submission
-------------------------------------------------------------------------------*/
add_action( 'gform_after_submission', 'add_confirmation_class', 10, 2 );
function add_confirmation_class() {
	add_filter('body_class', 'add_gravity_classes');
	function add_gravity_classes($classes){
		$classes[] = 'gravity-form-submitted';
		return $classes;
	}
}

If you want, you could also only add this for specific Gravity Forms by using ‘gform_after_submission_3’ instead of ‘gform_after_submission’ to target form ID 3. Then, all you need to do is add your CSS to hide elements when this class is present. I hope you enjoyed this post and find it helpful! If you have any questions or comments please post a comment or contact me.

 

Exit mobile version