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/' );
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 ); ajax gravity forms
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 } $form_id = intval( $_POST['form_id'] )
var formData = $form.serializeArray(); // Get all form data formData.push({ name: 'action', value: 'my_gf_submit_form' }); // Add action for admin-ajax formData.push({ name: 'security', value: my_ajax_obj.nonce }); formData.push({ name: 'form_id', value: formId }); $form = GFAPI::get_form( $form_id )