Skip to content

Instantly share code, notes, and snippets.

View richardW8k's full-sized avatar

Richard Wawrzyniak richardW8k

  • Rocketgenius, Inc (@gravityforms)
  • Lancashire, UK
  • 12:56 (UTC +01:00)
View GitHub Profile
/**
* Performs spam check and returns result to Gravity Forms.
*
* @param bool $is_spam Indicates if the entry is to be marked as spam.
* @param array $form The form currently being processed.
* @param array $entry The entry being evaluated.
*
* @return bool
*/
function your_gform_entry_is_spam_callback( $is_spam, $form, $entry ) {
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
if ( ! $result['is_valid'] && $field->get_input_type() === 'email' && GFCommon::is_valid_email_list( $value ) ) {
$result['is_valid'] = true;
$result['message'] = '';
}
return $result;
}, 10, 4 );
@richardW8k
richardW8k / gist:8d982aab66ace32a5e0d35ec7e2d6c1b
Last active July 30, 2019 10:06
Replace the Gravity Flow {workflow_cancel_link} merge tag when used in the step instructions.
add_filter( 'gform_pre_replace_merge_tags', function ( $text, $form, $entry ) {
if ( strpos( $text, '{workflow_cancel_link}' ) === false || empty( $entry ) || ! class_exists( 'Gravity_Flow_Merge_Tags' ) ) {
return $text;
}
$api = new Gravity_Flow_API( $form['id'] );
$step = $api->get_current_step( $entry );
if ( ! $step ) {
return $text;
@richardW8k
richardW8k / gw-gravity-forms-sum-nested-form-fields.php
Last active March 30, 2018 13:10 — forked from spivurno/gp-nested-forms-sum-nested-form-fields.php
Gravity Wiz // Gravity Perks // Get Sum of Nested Form Field Column
<?php
/**
* Gravity Wiz // Gravity Perks // Get Sum of Nested Form Fields
*
* Get the sum of a column from a Gravity Forms List field.
*
* @version 1.2
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/...
@richardW8k
richardW8k / RW_GF_Rating_Field_Logic.php
Last active April 28, 2016 17:29
enable support for using the Survey add-on rating type field with conditional logic - Survey Add-On version 3.0 includes this functionality so this snippet is no longer required
class RW_GF_Rating_Field_Logic {
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
function init() {
if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9.10', '>=' ) ) {
return;
}
@richardW8k
richardW8k / rw-gf-age-calculation.php
Last active April 24, 2019 06:14
calculate age from date field when age modifier specified on merge tag e.g. {Date of Birth:10:age}
<?php
class RW_GF_Age_Calculation {
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
function init() {
if ( ! class_exists( 'GFForms' ) || ! property_exists( 'GFForms', 'version' ) && version_compare( GFForms::$version, '1.9', '>=' ) ) {
@richardW8k
richardW8k / rw-gf-total-field-logic.php
Last active November 10, 2017 03:18
Enables use of the total field with conditional logic. [hide] this field if [total][less than][0.1] or [show] this field if [total][greater than][0]. Because the total field is always the last field to be saved you can't use it when configuring conditional logic on other fields. Displaying other fields based on the total would prevent those fiel…
<?php
class RW_GF_Total_Field_Logic {
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
function init() {
if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) {
return;
@richardW8k
richardW8k / extend_conditional_logic.php
Last active August 29, 2015 14:08
adding support for multi-input fields like the address field.
/*
Trigger conditional logic by adding an onclick or onchange event to your custom field input or by using something like the following
jQuery('#input_8_1 :input').on('change', function () {
gf_apply_rules(8, [2, 3, 4]);
});
*/
add_filter( 'gform_pre_render', 'extend_conditional_logic_frontend' );
function extend_conditional_logic_frontend( $form ) {
@richardW8k
richardW8k / GF_Field_Button.php
Last active August 29, 2015 14:05
Testing the GF_Field class in Gravity Forms 1.9
<?php
/**
* Plugin Name: Gravity Forms Button Field
* Last Modified: 18/08/2014
*/
if ( ! class_exists( 'GFForms' ) ) {
die();
}
@richardW8k
richardW8k / logging.php
Last active September 29, 2021 01:47
Logging statements for Gravity Forms.
<?php
add_filter( 'gform_pre_render', 'log_pre_render' );
function log_pre_render( $form ) {
GFCommon::log_debug( "log_pre_render(): \$form => " . print_r( $form, true ) );
return $form;
}
add_action( 'gform_pre_process', 'log_pre_process' );
function log_pre_process( $form ) {