Skip to content

Instantly share code, notes, and snippets.

Richard Wawrzyniak richardW8k

Block or report user

Report or block richardW8k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@richardW8k
richardW8k / gform_chosen_options
Last active Dec 20, 2015
for use with Gravity Forms to set options for enhanced ui drop downs, add to theme's functions.php file
View gform_chosen_options
// set options for chosen e.g disable search or set width to use percentage
add_action('gform_pre_render','set_chosen_options');
function set_chosen_options($form){
if(wp_script_is('gforms_chosen',$list='queue')){
?>
<script>
gform.addFilter('gform_chosen_options','set_chosen_options_js');
function set_chosen_options_js(options,element){
//options.placeholder_text_single = 'Selectionner une Option'; // set default placeholder for blank first option
//options.search_contains = true; // search options for partial matches
@richardW8k
richardW8k / form_settings_status
Last active Dec 27, 2015
adds form active/inactive status switch to Gravity Forms form settings page
View form_settings_status
// display form active/inactive status on the form settings view
add_filter('gform_form_settings', 'form_settings_status', 10, 2);
function form_settings_status($settings, $form){
$form_info = RGFormsModel::get_form($form["id"]);
$status_val = intval($form_info->is_active);
$status = $status_val ? __('Active', 'gravityforms') : __('Inactive', 'gravityforms');
$settings["Form Basics"]["form_status"] = "<tr><th><label>Form status</label></th><td><img class='gform_active_icon' src='".GFCommon::get_base_url()."/images/active{$status_val}.png' style='cursor:pointer;margin:5px 0 0 0;float:left;' alt='{$status}' title='{$status}' onclick='ToggleActive( this, {$form["id"]} );' /> <span class='gform_status' style='margin:3px 0 0 10px;float:left;' >{$status}</span></td></tr>";
return $settings;
}
// add script to settings page to allow toggling of active/inactive status
@richardW8k
richardW8k / ListFieldMaskedInput
Created Nov 14, 2013
add an input mask to an input in a Gravity Forms list field column
View ListFieldMaskedInput
// 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 / log_uploads
Last active Dec 28, 2015
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
View log_uploads
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 / ListFieldMaskedInput
Last active Dec 28, 2015
Activate input masks for List Field columns.
View ListFieldMaskedInput
add_filter('gform_enqueue_scripts_11', 'list_columns_mask_script');
function list_columns_mask_script() {
wp_enqueue_script( 'gform_masked_input', array( 'jquery' ), false, true );
}
add_filter('gform_register_init_scripts_11', 'list_columns_mask_init');
function list_columns_mask_init( $form ) {
$init = "";
/**
* Add a function call for each list field column you want to activate an input mask for
* $init .= "ListFieldMaskedInput( formId, fieldId, column, 'mask' );";
@richardW8k
richardW8k / ListFieldMaskedInput
Last active Dec 28, 2015
Activate input mask for list field columns. If no other field types have input masks enabled you will also need to enqueue the masked input script, see the following gist for an example https://gist.github.com/richardW8k/7529522
View ListFieldMaskedInput
<script>
function ListFieldMaskedInput( formId, fieldId, column, mask ){
jQuery( '.gfield_list_' + fieldId + '_cell' + column + ' input' ).mask( mask );
jQuery( '#field_' + formId + '_' + fieldId ).on( 'click', '.add_list_item', function(){
jQuery( '.gfield_list_' + fieldId + '_cell' + column + ' input' ).mask( mask )
});
}
ListFieldMaskedInput( 11, 2, 1, '9999' );
/**
* Add a function call for each list field column you want to activate an input mask for
@richardW8k
richardW8k / log_validation_failure
Last active Dec 31, 2015
Log Gravity Forms validation errors by adding the following code to your theme's functions.php file
View log_validation_failure
// log field validation errors
add_filter( 'gform_validation', 'log_validation_failure', 30 );
function log_validation_failure( $validation_result ) {
$form = $validation_result['form'];
foreach ( $form['fields'] as &$field ) {
if ( $field['failed_validation'] )
GFCommon::log_error( "form #{$form["id"]}: validate() - failed: {$field["label"]}({$field["id"]} - {$field["type"]}) - message: {$field["validation_message"]}" );
}
return $validation_result;
}
@richardW8k
richardW8k / radioProductOther
Last active Jan 1, 2016
set's value of radio product field other choice to value entered in fake text field
View radioProductOther
<input id="choice_1_3_other" type="text" value="" class="medium ginput_amount">
<script>
jQuery('#choice_1_3_other').change(function() {
var $other = jQuery('#choice_1_3');
var val = $other.val().split("|");
$other.val( val[0] + '|' + gformToNumber(jQuery(this).val()) );
gformCalculateTotalPrice(formId);
});
</script>
@richardW8k
richardW8k / calculatedShipping
Last active Jan 1, 2016
Script to set shipping price as the result of a calculated number field
View calculatedShipping
<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>
View listFieldDatepicker.js
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
});
You can’t perform that action at this time.