Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gravity Forms placeholder plugin. Slightly modified from here:
* 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="&lt;h6&gt;Placeholder&lt;/h6&gt;Enter the placeholder/default text for this field.">(?)</a>
<input type="text" id="field_placeholder" class="fieldwidth-3" size="35" onkeyup="SetFieldProperty('placeholder', this.value);">
<?php endif;
add_action('gform_field_standard_settings', 'my_standard_settings', 10, 2);
function my_gform_editor_js() { ?>
// binding to the load field settings event to initialize the checkbox
jQuery(document).bind('gform_load_field_settings', function(event, field, form){
<?php }
add_action('gform_editor_js', 'my_gform_editor_js');
function my_gform_enqueue_scripts($form, $is_ajax=false) { ?>
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; ?>
<?php }
add_action('gform_enqueue_scripts', 'my_gform_enqueue_scripts', 10, 2);

This comment has been minimized.

Copy link
Owner Author

@galengidman galengidman commented Apr 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment