Gravity Forms: Prevent Scrolling on Next / Previous Ajax Submits

###Step 1: Identify your Form ID

Figure out what your form ID is – look in the address bar as you edit your form:

Gravity Forms: Prevent Scrolling on Next / Previous Ajax Submits

###Step 2: Add a Filter

Edit something like your theme’s `functions.php` file and add a filter for the form number:

add_filter(‘gform_confirmation_anchor_5′,’theme_gform_confirmation_anchor_5’);

function theme_gform_confirmation_anchor_5($enabled)
{
return false;
}

###Step 3: Done

Now the code in the gravity forms plugin won’t fire that causes the form to scroll on ajax submits of multi-paged forms. (no need to change this, code for reference only):

if($use_anchor !== false) {
$scroll_position[‘default’] = is_numeric($use_anchor) ? “jQuery(document).scrollTop(” . intval($use_anchor) . “);” : “jQuery(document).scrollTop(jQuery(‘#gform_wrapper_{$form_id}’).offset().top);”;
$scroll_position[‘confirmation’] = is_numeric($use_anchor) ? “jQuery(document).scrollTop(” . intval($use_anchor) . “);” : “jQuery(document).scrollTop(jQuery(‘#gforms_confirmation_message’).offset().top);”;
}

###Step 4: Replace scrolling behavior with something like [jQuery Smooth Scroll](https://github.com/kswedberg/jquery-smooth-scroll)

Use code similar to this to scroll to a certain element after one of the submit buttons has been clicked:

Related Posts:

  • No Related Posts
This entry was posted in Tech Tips and tagged , . Bookmark the permalink.

One Response to Gravity Forms: Prevent Scrolling on Next / Previous Ajax Submits

Leave a Reply

Your email address will not be published. Required fields are marked *