Skip to content

Instantly share code, notes, and snippets.

@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 / 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>
<?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
}
// @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>
@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 );
@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 / gravity_forms_readonly.js
Last active August 18, 2021 14:58
This code snippet works for text input fields only and can be placed in an HTML field within your form.
<script type="text/javascript">
jQuery(document).ready(function(){
/* apply only to a input with a class of gf_readonly */
jQuery(".gf_readonly input").attr("readonly","readonly");
});
</script>
// Replace ID with your forms ID number.
body #gform_wrapper_ID .gform_footer input[type=submit] {
visibility: hidden;
}
<?php
// Do NOT include the opening php tag
// Replace 1 with your forms ID
// Replace User Notification with the name of your notification
// Insert your file path
add_filter( 'gform_notification_1', 'add_notification_attachments', 10, 3 );
function add_notification_attachments( $notification, $form, $entry ) {
if ( $notification['name'] == 'User Notification' ) {
$path = 'path/to/file.pdf';
@chrisegg
chrisegg / gforms_remove_button
Last active January 26, 2021 16:18
Replace the ID with your form ID number. Place this code in you functions.php file or a custom functions plugin
// Replace ID with your forms ID number.
add_filter( 'gform_submit_button_ID', '__return_false' );