Created
February 6, 2013 22:55
-
-
Save galengidman/4726661 to your computer and use it in GitHub Desktop.
Gravity Forms placeholder plugin. Slightly modified from here: http://www.wpbeginner.com/wp-tutorials/how-to-add-placeholder-text-in-gravity-forms/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add placeholder attributes to Gravity Form inputs. | |
*/ | |
function my_standard_settings($position, $form_id) { | |
if ($position == 25) : ?> | |
<li class="admin_label_setting field_setting" style="display:list-item;"> | |
<label for="field_placeholder">Placeholder Text | |
<a href="javascript:void(0);" class="tooltip tooltip_form_field_placeholder" tooltip="<h6>Placeholder</h6>Enter the placeholder/default text for this field.">(?)</a> | |
</label> | |
<input type="text" id="field_placeholder" class="fieldwidth-3" size="35" onkeyup="SetFieldProperty('placeholder', this.value);"> | |
</li> | |
<?php endif; | |
} | |
add_action('gform_field_standard_settings', 'my_standard_settings', 10, 2); | |
function my_gform_editor_js() { ?> | |
<script> | |
// binding to the load field settings event to initialize the checkbox | |
jQuery(document).bind('gform_load_field_settings', function(event, field, form){ | |
jQuery('#field_placeholder').val(field['placeholder']); | |
}); | |
</script> | |
<?php } | |
add_action('gform_editor_js', 'my_gform_editor_js'); | |
function my_gform_enqueue_scripts($form, $is_ajax=false) { ?> | |
<script> | |
jQuery(function() { | |
<?php foreach ($form['fields'] as $i=>$field) : ?> | |
<?php if (isset($field['placeholder']) && ! empty($field['placeholder'])) : ?> | |
jQuery('#input_<?php echo $form['id']?>_<?php echo $field['id']?>').attr('placeholder', '<?php echo $field['placeholder']?>'); | |
<?php endif; ?> | |
<?php endforeach; ?> | |
}); | |
</script> | |
<?php } | |
add_action('gform_enqueue_scripts', 'my_gform_enqueue_scripts', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nevermind. This is a better solution: http://wordpress.org/extend/plugins/gravity-forms-placeholders/