Adding a query parameter to Gravity Forms ajax endpoint in js

Hi All,

Just wondering if its possible to add a query string parameter to gravity forms ajax endpoint so that it will post/get with something like admin-jax.php?param=1

Thanks

Hi GravityDev,

You can definitely add a query string parameter to the Gravity Forms AJAX endpoint.

  1. First, you need to add the following custom JavaScript to your website. You can do this by putting the code in your theme’s JavaScript file or using a plugin that allows you to add custom scripts.
  2. Copy and paste the following code into your JavaScript file:
jQuery(document).ready(function($) {
    $(document).on('gform_post_render', function(event, formId) {
        // Change 1 to your actual form ID
        if (formId === 1) { 
            var originalAjaxUrl = gform.ajaxurl;

            // Add your parameter here
            gform.ajaxurl = originalAjaxUrl + '?param=1'; 
        }
    });
});
  1. Make sure to change 1 to match the ID of your Gravity Form.
  2. After you save the changes, test your form to ensure it’s working correctly with the new parameter.

This code will add ?param=1 to the AJAX request whenever that specific form is submitted.

For more details, please have a look at the following documentation.

Give it a try, and let me know how that goes! :grinning_face_with_smiling_eyes: