wp_send_json_error( array( 'validation_html' => $validation_html ) ); } else { // Success! Define a redirect URL (from confirmation or custom) $confirmation = GFFormDisplay::handle_confirmation( $form, $entry, false ); $redirect_url = is_array( $confirmation ) && isset( $confirmation['redirect'] ) ? $confirmation['redirect'] : home_url( '/thank-you/' );
For WordPress site owners, this traditional, synchronous form submission has long been the default behavior of Gravity Forms, the premium plugin powering millions of websites. It works. It's reliable. But in an era of single-page applications and instant feedback, the full-page reload feels clunky, disorienting, and slow. ajax gravity forms
var formData = new FormData(this); formData.append('action', 'my_gf_submit_form'); formData.append('security', my_ajax_obj.nonce); $.ajax({ url: my_ajax_obj.ajax_url, type: 'POST', data: formData, contentType: false, // Important for file uploads processData: false, // ... rest of AJAX config }); It works
This custom approach gives you complete control. You can close modal popups, play success sounds, trigger analytics events, or animate a custom thank-you message—all without ever leaving the page. Even with a solid understanding, AJAX and Gravity Forms can present challenges. var formData = new FormData(this); formData
function my_gf_ajax_submit_handler() { // Verify nonce if ( ! wp_verify_nonce( $_POST['security'], 'gf_ajax_nonce' ) ) { wp_die('Security check failed'); } $form_id = intval( $_POST['form_id'] ); $form = GFAPI::get_form( $form_id );
However, this built-in solution, while powerful, is the "lowest common denominator." It works reliably, but it lacks customization. The confirmation message fades in, the errors appear, but you have limited control over what happens next . What if you want to redirect to a custom "thank you" page using AJAX ? What if you want to close a modal window upon successful submission? What if you need to track the submission in Google Analytics?
Gravity Forms uses JavaScript to handle conditional logic (showing/hiding fields). If you load a form via AJAX into a modal, you must re-initialize Gravity Forms' scripts: