Skip to content

Instantly share code, notes, and snippets.

View richardW8k's full-sized avatar

Richard Wawrzyniak richardW8k

  • Rocketgenius, Inc (@gravityforms)
  • Lancashire, UK
  • 15:01 (UTC +01:00)
View GitHub Profile
@richardW8k
richardW8k / button_filters.php
Last active April 29, 2022 18:37
convert the next, previous and/or submit button <input> to <button> and uses the input value to create the button text inside a <span>, this means you can set the button text by editing the form or page break settings.
<?php
/**
* Filters the next, previous and submit buttons.
* Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
* @param string $button Contains the <input> tag to be filtered.
* @param object $form Contains all the properties of the current form.
* @return string The filtered button.
*/
add_filter( 'gform_next_button', 'input_to_button', 10, 2 );
add_filter( 'gform_previous_button', 'input_to_button', 10, 2 );
@richardW8k
richardW8k / radio_input_inside_label.php
Last active May 14, 2020 04:49
move a Gravity Forms radio input inside the label
<?php
// move radio input inside label
add_filter("gform_field_choices", "radio_input_inside_label", 10, 2);
function radio_input_inside_label($choices, $field){
if($field["type"] != "radio")
return $choices;
$choices = "";
@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 / 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;
<?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 / RWNotificationExtras.php
Last active September 30, 2021 21:17
Adds a new settings to Gravity Forms notifications allowing uploaded files to be attached to the notification and the notification format to be changed to text.
<?php
/**
* Plugin Name: Gravity Forms - Notification Extras
* Author: Richard Wawrzyniak
* Description: Adds new settings to Gravity Forms Notifications enabling file uploads to be attached to notifications and the notification format to be changed to text.
* Version: 1.0
*
* Last Modified: 17/10/2014
* Updated attach_file() to allow for possibility that uploads folder was changed
* Added suppot for post_image fields
@richardW8k
richardW8k / RW_Delete_Entry.php
Last active January 20, 2022 07:21
When placed in the theme functions.php file this will add a checkbox to the 'Form Options' part of the Form Settings page which when checked will cause entries to be automatically deleted at the end of the submission process.
<?php
class RW_Delete_Entry {
function __construct() {
if( ! property_exists( 'GFCommon', 'version' ) || ! version_compare( GFCommon::$version, '1.8.5.8', '>=' ) )
return;
add_filter( 'gform_tooltips', array( $this, 'add_delete_tooltip') );
add_filter( 'gform_form_settings', array( $this, 'add_delete_setting' ), 10, 2 );
add_action( 'gform_pre_form_settings_save', array( $this, 'save_delete_setting' ), 10 );
add_action( 'gform_after_submission', array( $this, 'maybe_delete_form_entry' ), 15, 2 );
@richardW8k
richardW8k / rw_change_checkbox_structure.php
Created March 19, 2014 16:15
change Gravity Forms checkbox structure so it doesn't use the extra ul and li's
add_filter( 'gform_field_input', 'rw_change_checkbox_structure', 10, 5 );
function rw_change_checkbox_structure($input, $field, $value, $lead_id, $form_id){
$input_type = RGFormsModel::get_input_type($field);
if($input_type != "checkbox" || IS_ADMIN && RG_CURRENT_VIEW == "entry")
return $input;
$choices = "";
if(is_array($field["choices"])){
$choice_number = 1;
@richardW8k
richardW8k / change_column_to_checkbox.php
Created May 3, 2014 11:02
To convert a list field column to use a checkbox add the php excluding the first line to your theme functions.php file. The JavaScript can be placed between script tags in a HTML field on the form.
<?php
// format: gform_column_input_content_FORMID_FIELDID_COLUMN
add_filter( 'gform_column_input_content_524_2_2', 'change_column_to_checkbox', 10, 6 );
function change_column_to_checkbox( $input, $input_info, $field, $text, $value, $form_id ) {
$input_field_name = "input_{$field['id']}[]";
$tabindex = GFCommon::get_tabindex();
$new_input = "<input type='checkbox' {$tabindex} /><input type='hidden' name='{$input_field_name}' value=' ' />";
return $new_input;
}
@richardW8k
richardW8k / change_col_to_checkboxes.php
Created May 3, 2014 16:14
To convert a list field column to use checkboxes add the php excluding the first line to your theme functions.php file. The JavaScript can be placed between script tags in a HTML field on the form.
<?php
// format: gform_column_input_content_FORMID_FIELDID_COLUMN
add_filter( 'gform_column_input_content_524_2_2', 'change_column_to_checkbox', 10, 6 );
function change_column_to_checkbox( $input, $input_info, $field, $text, $value, $form_id ) {
$input_field_name = "input_{$field['id']}[]";
$tabindex = GFCommon::get_tabindex();
$new_input = "<div class='ginput_container'><ul class='gfield_checkbox'>" .
"<li><input type='checkbox' {$tabindex} value='First Choice' /><label>First Choice</label></li>" .
"<li><input type='checkbox' {$tabindex} value='Second Choice' /><label>Second Choice</label></li>" .
"</ul><input type='hidden' name='{$input_field_name}' value='' /></div>";