Skip to content

Instantly share code, notes, and snippets.

@galengidman
Created February 6, 2013 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save galengidman/4726661 to your computer and use it in GitHub Desktop.
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/
/**
* 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>
</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);
@galengidman
Copy link
Author

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