Skip to content

Instantly share code, notes, and snippets.

View richardW8k's full-sized avatar

Richard Wawrzyniak richardW8k

  • Rocketgenius, Inc (@gravityforms)
  • Lancashire, UK
  • 22:14 (UTC +01:00)
View GitHub Profile
@richardW8k
richardW8k / ListFieldMaskedInput
Created November 14, 2013 16:54
add an input mask to an input in a Gravity Forms list field column
// enable input mask for form #95 list field #3 columns 1 and 3
add_filter('gform_register_init_scripts_95', 'enable_list_input_mask');
function enable_list_input_mask($form) {
$field_id = "3"; //set field id here
$col_id = array('1','3'); //set column id here
$mask = "9999"; //define mask here, examples at http://www.gravityhelp.com/documentation/page/Input_Mask
//that's it nothing more to configure
$c_sel = array();
foreach($col_id as $c) {
@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 / 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 );
function listFieldDatepicker(formId, fieldId, column) {
var listField = '#field_' + formId + '_' + fieldId,
columnClass = '.gfield_list_' + fieldId + '_cell' + column + ' input';
jQuery.datepicker.setDefaults({
showOn: 'both',
buttonImage: '/wp-content/plugins/gravityforms/images/calendar.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
firstDay: 1
});
@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 / 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 ) {
/**
* 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 ) {
@richardW8k
richardW8k / log_uploads
Last active July 14, 2021 17:10
Logs file uploads for single file and multi-file upload fields pre and post submission to the Gravity Forms logging add-on: http://www.gravityhelp.com/downloads/#Gravity_Forms_Logging_Tool
add_action( 'gform_pre_submission_8', 'uploads_log_pre_submission' );
function uploads_log_pre_submission( $form ) {
foreach ( $form["fields"] as &$field ) {
if ( $field["type"] == "fileupload" ) {
$id = "input_".$field["id"];
if ( $field["multipleFiles"] ) {
if ( empty( $_POST["gform_uploaded_files"] ) )
continue;
@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 / RW_Button_Field.php
Last active January 15, 2020 08:44
Adds a Button field type allowing you to add extra buttons to the form, supported type are button, submit and reset.
<?php
/**
* Plugin Name: Gravity Forms - Button Field
* Last Modified: 22/06/2014
*/
class RW_Button_Field {
function __construct() {
if( ! property_exists( 'GFCommon', 'version' ) || ! version_compare( GFCommon::$version, '1.8', '>=' ) )