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/' );
wp_send_json_success( array( 'redirect_url' => $redirect_url ) ); } } add_action( 'wp_ajax_my_gf_submit_form', 'my_gf_ajax_submit_handler' ); add_action( 'wp_ajax_nopriv_my_gf_submit_form', 'my_gf_ajax_submit_handler' ); ajax gravity forms
Traditional AJAX using serializeArray() does not handle file inputs. For forms with file uploads, you need to use the FormData API: For forms with file uploads, you need to
jQuery(document).ready(function($) { var formId = 1; // Change this to your form's ID var $form = $('#gform_' + formId); $form.on('submit', function(e) { e.preventDefault(); // Stop normal submission It works
if ( empty( $result['is_valid'] ) ) { // Validation failed. Get the validation HTML. ob_start(); GFFormDisplay::get_form( $form_id, true, true ); $validation_html = ob_get_clean();
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.