Skip to content

Instantly share code, notes, and snippets.

@chrisegg
chrisegg / hide-gravityforms-admin-header.php
Created September 6, 2021 13:58
Hide the Gravity Forms brand header in the WP Admin that was added in v2.5.
<?php
//Copy everything below this point
add_action( 'admin_head', function () { ?>
<style>
header.gform-settings-header .gform-settings__wrapper {
/* this will hide the whole thing, including image */
display: none;
}
@chrisegg
chrisegg / gf-limit-payments.php
Last active September 6, 2021 14:43
Limit Stripe Subscriptions to a Specified Number of Payments
<?php
//Code provided by Gravity Forms here: https://rocketgenius.pxf.io/limit-payments
//Start copying below this line...
add_action( 'gform_post_add_subscription_payment', function ( $entry ) {
gf_stripe()->log_debug( "Running..." );
if ( rgar( $entry, 'payment_status' ) == 'Active' ) {
$feed = gf_stripe()->get_payment_feed( $entry );
// @credits https://docs.gravityforms.com/adding-an-inline-submit-button-in-gravity-forms-2-5/
// You will need to replace 123 in gform_submit_button_123 and gform_wrapper_123 with your forms ID number
// Copy everything below this line.
<div>
<button onclick="document.getElementById('gform_submit_button_123').click();" style="height: 2.5rem;padding:0 1rem;font-size:1rem;">
Submit
</button>
</div>
<?php
// Copy everything below this line
add_filter( 'gform_field_value_default_quantity', 'gr_default_qty' );
function gr_default_qty() {
return 0; // change this number to your desired default quantity
}
@chrisegg
chrisegg / auto-advance-radio-select-fields.js
Created November 20, 2021 19:20
This snippet will support auto advancing pages in multi-page form for radio button and drop down field types. Full tutorial here: https://gravityranger.com/how-to-build-a-conversational-form-in-gravity-forms
<script>
jQuery(document).ready(function($) {
$('input[type=radio], select').on('change', function() {
$(this).closest("form").submit();
});
});
</script>
@chrisegg
chrisegg / login-logout-shortcode.php
Created December 16, 2021 19:51
GravityRanger - Login/Logout Shortcode
<?php
//copy everything below this line
/**
* GravityRanger Login Logout Shortcode
*
* Creates a login/logout shortcode button
* https://gravityranger.com/login-logout-shortcode-for-gravity-forms-membership-sites/
*
* Used for creating a login/logout shortcode to be used with a WordPress website.
@chrisegg
chrisegg / gf-dual-confirmation.php
Last active March 26, 2023 20:37
Uses the gform_confirmation hook to display a text confirmation message before triggering the redirect confirmation.
<?php
// Copy everything below this line
/**
* GravityRanger Dual Confirmation (text + redirect)
* https://gravityranger.com/display-text-confirmation-before-redirecting-gravity-forms
*
* Uses the gform_confirmation hook to display a text confirmation message before triggering the redirect confirmation.
* This code is a modified version of the snippet provided on docs.gravityfroms.com
*
@chrisegg
chrisegg / gf-text-redirect-confirmaton.js
Last active December 20, 2021 20:18
Use this code snippet if you'd like to display a text confirmation before redirecting the user to another page/url with Gravity Forms.
/**
* GravityRanger
* https://gravityranger.com/display-text-confirmation-before-redirecting-gravity-forms/
*
* Used to display a text message after a form is submitted, but triggers a redirect 2 seconds after message is displayed.
*
* Instructions: Copy and paste lines 11-17 into a Gravity Forms text confirmaton. Make any necessary changes to the text or number of seconds, i.e 2000 = 2 seconds, (line 16).
*
*/
<?php
//Copy everything below this line
/**
* GravityRanger Change Submit Button Text
*
* Allows you to change the submit button text after the button is clicked.
* https://gravityranger.com/change-gravity-forms-submit-button-text-after-submission/
*
* @instructions:
@chrisegg
chrisegg / form-auto-submit.js
Created February 12, 2022 23:58
Allows you to auto-submit a form when the page loads, with a 1/2 second delay. Full tutorial here: https://gravityranger.com/auto-submit-form-page-load/
/**
* GravityRanger Auto-Submit Form on Page Load
*
* Allows you to auto-submit a form when the page loads, with a 1/2 second delay.
* https://gravityranger.com/auto-submit-form-page-load/
*
* @instructions:
*
* 1. Change gform_ID# to your forms ID number (line 24)
* 2. Set the amount of time you'd like to delay the script (line 27)