- Tags: Form, Gravity Forms
- Categories: Snippets, WordPress Snippets
Code Snippet
When using Gravity Forms you can decide on a per-form basis as to whether or not you want to automatically scroll to the page top after a form submit.
There are times when a form is towards the bottom of the page and you want the screen to stay in that position so that the user can see the confirmation text. Other times, you may want the page to scroll back to the top because the form is long and the confirmation text will be towards the top.
PHP
Don't Scroll to the Top
Place the following code anywhere in your theme’s functions.php document. Make sure to change the forms to the actual one’s you don’t want to scroll. You can list as many forms here as necessary (we are listing two forms).
// don't scroll to the top of page after submit
add_filter( 'gform_confirmation_anchor_1', '__return_false' );
add_filter( 'gform_confirmation_anchor_4', '__return_false' );
Do Scroll to the Top
Place the following code anywhere in your theme’s functions.php document. These are the forms we want to scroll back to the page top after begin submitted.
// do scroll to the top of page after submit
add_filter( 'gform_confirmation_anchor_2', function() { inquiry
return 0;
} );
add_filter( 'gform_confirmation_anchor_3', function() { inquiry
return 0;
} );
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.
Why 1SMARTchicken?
See More →
Thanks for your support!
WordPress Books
All are affiliate links. Thank you for your support!
WORDPRESS NOTES:
- All modifications to a theme or plugin should be made by creating a child theme and placing the changes there; changes made to the parent theme will be overwritten the next time it updates
Feedback
If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.