Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View richardW8k's full-sized avatar

Richard Wawrzyniak richardW8k

  • Rocketgenius, Inc (@gravityforms)
  • Lancashire, UK
  • 16:11 (UTC +01:00)
View GitHub Profile
@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 / 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', '>=' ) ) {
<?php
add_filter( 'gform_calculation_formula', 'sum_list_column', 10, 4 );
function sum_list_column( $formula, $field, $form, $lead ) {
// {List:1.3} - {Label:ID.Column}
preg_match_all( '/{[^{]*?:(\d+?).(\d+?)}/mi', $formula, $matches, PREG_SET_ORDER );
if( is_array( $matches ) ) {
foreach( $matches as $match ) {
@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-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;
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 / rw_change_radio_structure.php
Last active November 3, 2016 16:42
Change the structure of Gravity Forms radio fields so it doesn't use the extra ul and li's
add_filter( 'gform_field_input', 'rw_change_radio_structure', 10, 5 );
function rw_change_radio_structure($input, $field, $value, $lead_id, $form_id){
$input_type = RGFormsModel::get_input_type($field);
if($input_type != "radio" || IS_ADMIN && RG_CURRENT_VIEW == "entry")
return $input;
$choices = "";
if(is_array($field["choices"])){
$choice_id = 0;
@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 / validate_uk_phone.php
Last active March 31, 2016 17:51
add to theme functions.php file to add uk as an available format on the phone type field and validation of uk style numbers, pattern from: http://www.coffeecup.com/help/articles/regular-expression-examples/#phonenumber-uk
<?php
//checks to see if a string is a valid UK phone number
add_filter( 'gform_field_validation', 'validate_phone', 10, 4 );
function validate_phone( $result, $value, $form, $field ) {
$pattern = "/^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/";
if ( $field->type == 'phone' && $this->phoneFormat != 'standard' && ! preg_match( $pattern, $value ) ) {
$result['is_valid'] = false;
$result['message'] = 'Please enter a valid phone number';
}
@richardW8k
richardW8k / calculatedShipping
Last active January 1, 2016 07:49
Script to set shipping price as the result of a calculated number field
<script>
gform.addFilter( 'gform_calculation_result', function(result, formulaField, formId, calcObj ){
if ( formulaField.field_id == "4" ){
jQuery(".ginput_shipping_price").html(gformFormatMoney(result)).prev('input').val(gformFormatMoney(result));
gformCalculateTotalPrice( formId );
}
return result;
});
</script>