Ask WordPress Girl

Custom themes, tips, classes, and resources
  • Facebook
  • Feedburner
  • Google
  • Linkedin
  • Pinterest
  • Twitter
  • Home
  • Hosting
  • Security
  • Installing
  • Customizing
  • Plugins
  • Links
  • About
Home / Plugins / Gravity Forms Placeholder Text that Works with IE

Gravity Forms Placeholder Text that Works with IE

January 20, 2012 / Angela / Plugins / 29 Comments

Surprisingly Gravity Forms hasn’t implemented the placeholder feature for Gravity Forms input elements. The placeholder allows you to show placeholder text inside the field instead of using field labels to create more concise looking forms like this:

On June 22, 2011, Jorge Pedret, a freelance web developer, came up with a solution to the Gravity Forms placeholder problem with a clever function and script that could be added to your theme’s functions.php file. Unfortunately, the solution he posted didn’t work with non-html 5 compliant browsers, such as IE 7 and IE 8.

On September 15, 2011, WP Beginner reposted Jorge’s solution, yet it still didn’t work on IE. Luckily, an astute reader of WP Beginner, chood531, solved the problem and posted some code on pastebin, however, the code was only partial, so not the complete solution and validation errors ended up removing the placeholder values in IE 8, so the form was inscrutable.

Luckily, a cool programmer created a nifty plugin to take care of all of this: Gravity Forms Placeholders Add-on. (There is another plugin called Gravity Forms Auto Placeholders, but it’s a bit buggy with IE 8 which sort of defeats the purpose. It can conflict with other Javascript on the site as well.)

To use the Gravity Forms Placeholders Add-On plugin, go to Plugins > Add New and search for Gravity Forms Placeholder. Install the one by Joan Piedra.

After installing the plugin, edit each of your forms. For each field on the form, click the Advanced tab. In the CSS Class Name field, type: gplaceholder

Save your changes. This will now use the field label as the placeholder text on the form.

Gravity Forms Placeholder

Share this:

  • More

29 comments on “Gravity Forms Placeholder Text that Works with IE”

  1. Ian Sterne says:
    February 21, 2012 at 8:16 am

    Thanks WordPress Girl:

    This looks like it is going to work for me I am just having one problem. I am changing the CSS to work with my site and have changed the input text color and that works fine, but the placeholder text is still light grey and I can not find the CSS to change it. 

    Could you tell me the CSS selector for the placeholder text please?

    Reply
    • Anonymous says:
      February 21, 2012 at 8:51 am

      .gform_wrapper .top_label select.medium

      I had to preface this with the div I had it in on my site in order to change this in my custom.css file.

      Check functionality on IE 7 and 8. I changed the jquery for this to onfocus, because the text was completely disappearing. I’ll put new code above.

      Reply
      • Ian Sterne says:
        February 21, 2012 at 9:46 am

        Found it 

        input::-webkit-input-placeholder, textarea::-webkit-input-placeholder{    color:    #45290F;}input:-moz-placeholder, textarea:-moz-placeholder {    color:    #45290F;}

        Reply
        • Anonymous says:
          February 21, 2012 at 10:09 am

          Not sure that will work across browsers. How about this:

          .custom .gform_wrapper input { color: #45290F; } – for the color you want to use for the user’s input of text in the fields

          .gform_wrapper .top_label select..gform_wrapper .top_label input.large, .gform_wrapper .top_label select.large, .gform_wrapper .top_label textarea.textarea – for the placeholder text { color: #45290F; }

          You’ll see both of these using Firebug. What version of Firefox are you using? The above works with current version of FF.

          Reply
          • Ian Sterne says:
            February 21, 2012 at 10:28 am

            Firefox shows the brown by default but webkit browsers show grey, I do most of my development work in Chrome

          • Anonymous says:
            February 21, 2012 at 10:33 am

            Thanks for the information! I’ll do some more research and append this post with some suggested CSS selectors for this.

    • Anonymous says:
      February 21, 2012 at 8:55 am

       I just changed the jquery for IE, so please recopy the code. I added onfocus: ‘this.select();’}); to make it function better in IE when people clicked in the input box.

      Reply
  2. Derek says:
    February 22, 2012 at 5:31 pm

    I have successfully implemented this, however in Chrome, when a user clicks on an input field the text does not clear or disappear. In Firefox it does. Anybody have any clue why this is the case?

    Reply
    • Anonymous says:
      February 23, 2012 at 9:04 am

      This might work:

      input:focus::-webkit-input-placeholder {
      color: transparent;
      }

      Reply
      • Anonymous says:
        February 23, 2012 at 9:11 am

         Yup, the above works in the stylesheet, but you may need to preface it with the div and perhaps .gform_wrapper. In my stylesheet, I entered it like this:

        #sidebar .gform_wrapper input:focus::-webkit-input-placeholder {
        color: transparent;
        }

        Reply
      • Derek says:
        February 23, 2012 at 9:39 am

        Worked like a charm. Thank you.

        Reply
        • Anonymous says:
          February 23, 2012 at 1:57 pm

          Awesome!

          Reply
  3. Jonathan Goldford says:
    April 12, 2012 at 10:30 pm

    I really like what you proposed and I actually used it along with the jQuery Placeholder plugin (https://github.com/mathiasbynens/jquery-placeholder) to make it work with IE.  The problem I am running in to is that if the form reloads with validation errors then the placeholder text is not added.  Any ideas on how to fix this?

    Reply
  4. Jonathan Goldford says:
    April 16, 2012 at 1:50 pm

    After running into a couple of issues, I finally figured out a way to do this that doesn’t require javascript to be run on the front end and actually places the placeholder attribute in from the start.  I’d love to hear your thoughts Angela.

    Basically, replace the last action call for gform_enqueue_scripts and the function with this:

    add_filter(“gform_field_content”, “wi_gform_add_placeholder”, 10, 5);function wi_gform_add_placeholder($content, $field, $value, $lead_id, $form_id){  if (isset($field['placeholder']) && !empty($field['placeholder'])) {    $content = str_replace(‘id=’, ‘placeholder=”‘ . $field['placeholder'] . ‘” id=’, $content);        return $content;  }    return $content;}

    That will add the placeholder if it exists or return the original field content if it doesn’t exist.

    Reply
    • AskWPGirl says:
      April 16, 2012 at 4:47 pm

      Hi Jonathan,

      I’ll test that out. Does it work on IE 7 and IE 8?

      Reply
      • Jonathan Goldford says:
        April 19, 2012 at 2:11 pm

        It will work in IE7 and IE8 as long as you use the jQuery Placeholder plugin (
        https://github.com/mathiasbynens/jquery-placeholder).

        Reply
  5. Curtis Broom says:
    May 30, 2012 at 7:45 pm

    Guys, I came up with a solution for placeholder using the title value. 

    function placeholder(){ $(“input[type=text]“).each(function(){ var titleValue = $(this).attr(“title”); if ($(this).val() == “”) { $(this).val(titleValue); $(this).css(‘color’, ‘#a6a6a6′); } }); } placeholder(); $(“input[type=text]“).focusin(function(){ var titleValue = $(this).attr(“title”); if ($(this).val() == titleValue) { $(this).val(“”); $(this).css(‘color’, ‘#333′); } }); $(“input[type=text]“).focusout(function(){ var phvalue = $(this).attr(“title”); if ($(this).val() == “”) { $(this).val(phvalue); $(this).css(‘color’, ‘#a6a6a6′); } });

    Reply
  6. Clauderic Demers says:
    July 15, 2012 at 8:01 pm

    Great solution. Any way to make it work with http://wpml.org/documentation/related-projects/gravity-forms-multilingual/? I can’t seem to get it to work

    Reply
  7. Clauderic Demers says:
    July 15, 2012 at 8:25 pm

    Nevermind, found a much more convenient solution without even having to use this solution to start with. Placeholders are generated with the actual label value:

    jQuery(‘.gfield’).each(function(index) { var labelval = jQuery(this).find(‘label’).text(); jQuery(this).find(‘input, textarea’).attr(‘placeholder’, labelval);});

    Reply
  8. Christi Richards says:
    August 5, 2012 at 2:26 pm

    Thanks for sharing this – was able to tweak this to be exactly what I needed for a project I’m working on.

    Reply
    • AskWPGirl says:
      August 6, 2012 at 4:03 pm

      Hi Christi, I will be rewriting this post as there is now a new plugin you can get and not deal with this code. http://wordpress.org/extend/plugins/gravity-forms-auto-placeholders/ This plugin is great because it will work correctly IE 7 and IE 8 with validation errors. So skip all my instructions and just install the plugin, and you’re good to go!

      Reply
  9. Jesse says:
    September 18, 2012 at 8:21 pm

    Thanks for all the info. Do any of these plugins/code snippets allow for place holders in advanced form elements with multiple fields? For example the email field with confirmation (put a place holder in both the first and second email field) or the “address” field (put place holder for street address, address line 2, city, etc…).

    Reply
    • AskWPGirl says:
      September 19, 2012 at 12:45 pm

      Hi Jesse,

      I’m going to rewrite this post and remove ALL of the code here and instead recommend that people use a new plugin called Gravity Forms Auto Placeholders: http://wordpress.org/extend/plugins/gravity-forms-auto-placeholders/

      It works like a charm, and you don’t have to muck with any code or even having to assign placeholder values. I’ll put up a screenshot with example forms.

      Reply
      • Jesse says:
        September 19, 2012 at 12:49 pm

        Yeah, I saw your recommendation for that plugin. I just wanted to know if it has the functionality I specified in my first comment (placeholders for advanced fields). If not, are you aware of anything that does allow for this? Thanks.

        Reply
        • AskWPGirl says:
          September 24, 2012 at 9:19 pm

          Yes, it does work with the advanced fields. For example, the Name field which automatically creates First and Last name fields. However, it also adds the field label “Name” to the placholder value, eg. “NameFirst.” So, you’ll want to delete the label for the advanced fields, so it doesn’t get included along with the placholder value if that makes sense. Certainly worth trying out!

          Reply
      • Greg says:
        October 11, 2012 at 4:35 pm

        Hi Angela,
        The “Gravity Forms Auto Placeholders” plugin has a bug on IE9 where the form shows that the form data was submitted successfully but the notification email address does not receive the form data. If you simply want to hide labels and replace them with placeholders, the “Gravity Forms – Placeholders add-on” plugin works well.

        Reply
        • AskWPGirl says:
          November 4, 2012 at 12:45 pm

          Hi Greg,

          I have had the Gravity Forms – Placeholders Add-on plugin not work at all on some sites. So, it would seem that both of these plugins have the potential of conflicting with other plugins or Javascript on the site. The plugin I recommended works great on the sites I’m using it on and the plugin you recommend doesn’t. So, it seems to be sensitive. The problem I have found with the one I recommend is that if validation fails for a field, it doesn’t always validate for the required fields. I think Gravity Forms really needs to integrate placeholder values in a future release.

          Reply
  10. Chris Waldron says:
    November 26, 2012 at 2:08 pm

    Not so often do I find code on a blog that not only works but works flawlessly for exactley what I need! This works in Studiopress themes sans the start and end PHP tags. Looks great in all browsers although Chrome is a little too light of a gray but who cares. I just needed it for a text box for details at the end of a form. Nor sure why this isn’t standard equipment in GF.

    Thanks so much for posting this! Also the copy to clipboard button isnt working anymore and if you select all the text you get the line numbers with it. Only way to get it clean now is the view source button. Maybe that’s by design?

    Reply
    • AskWPGirl says:
      November 26, 2012 at 5:43 pm

      Hi Chris,

      I’m glad the code worked for you. However, if there are validation errors, I’ve found that in IE 8, the field values do not display again, which is a problem. So, I’ve been using one of the two plugins listed below in the previous comments, and they work great and then you don’t have to mess around with all this code.

      Reply

Leave a Reply Cancel reply

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 32 other subscribers

Upcoming Classes

with Ask WP Girl

  • Customizing WordPress Themes

    February 18-March 6, 2013
    Hands On Intensive

  • WordPress – Essential Plugins

    March 20 or June 6, 2013

  • WordPress Security and Backup

    April 15, 2013

  • WordPress – Creating Image Galleries

    Summer 2013 (tba)

Share this:

  • More

Share this:

  • More

Recent Posts

  • How to Protect Your Site from the Botnet Hack

    April 13, 2013
  • Create an Image Gallery in WordPress Using a Lightbox Plugin

    February 7, 2013
  • Fancy Borders for NextGEN Gallery Galleries

    November 9, 2012
  • Gravity Forms Placeholder Text that Works with IE

    January 20, 2012
  • Moving WordPress from Subdirectory to Root – FAQ

    November 19, 2011
  • Customizing Studio Press Child Themes

    September 5, 2011
  • TimThumb WordPress Security Vulnerability

    August 30, 2011
  • 25 Top WordPress Plugins You Should Know About

    August 2, 2011
  • How do I move WordPress from a subdirectory to the root directory?

    January 25, 2011
  • Finding a Web Host and Installing WordPress

    January 6, 2011

Categories

  • Answers to Your Questions
  • Customizing
  • Getting Started
  • Hosting
  • Installing
  • NextGen Gallery
  • Plugins
  • Resources
  • Security
(c) 2013 Ask WP Girl - Angela Bowman
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.