Created
October 25, 2013 20:13
-
-
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
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
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