Skip to content

Instantly share code, notes, and snippets.

@aduth
Created October 25, 2013 20:13
Show Gist options
  • Save aduth/7161133 to your computer and use it in GitHub Desktop.
Save aduth/7161133 to your computer and use it in GitHub Desktop.
Gravity Forms placeholders using a combination of default value and "gforms-placeholder" class
function enable_gforms_placeholders($content, $field, $value, $lead_id, $form_id) {
if (strpos($field['cssClass'], 'gforms-placeholder') !== false) {
switch ($field['type']) {
case 'text':
case 'phone':
case 'website':
case 'number':
case 'name':
case 'address':
case 'email':
$content = preg_replace('/<\s*input(.*) value=[\'"]([^\'"]+)[\'"](.*)(\/>|>\s*<\/input>)/', '<input$1 placeholder="$2"$3$4', $content);
break;
case 'textarea':
$content = preg_replace("/<\s*textarea([^>]*)\s*>(.+)<\/\s*textarea\s*>/", '<textarea placeholder="$2"$1></textarea>', $content);
break;
default: break;
}
}
return $content;
}
add_filter('gform_field_content', 'enable_gforms_placeholders', 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment