PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Placeholder text breaking on AJAX validation

  1. It seems that all the suggestions made in the past for using plugins to create form placeholders based on the labels don't seem to work that great with the AJAX forms.

    Every plugin i've tried successfully replaces the labels with input placeholders, but as soon as the form is submitted with blank required fields, all the placeholders disappear and the labels reappear. It's far from ideal. The designs i need to work to require the use of placeholders due to the tight space available for the form.

    It's a shame placeholder text (including modernizr fallbacks for old browsers) isn't included by default. It seems like a common feature request.

    So my question is: Is there anyway to get the placeholders to work with the AJAX validation?

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink
  2. David Peralty

    Can you link to your form? I'm not sure I understand what you mean by placeholders.

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink
  3. Ah, I mean HTML5 input placeholders.

    E.g:

    http://davidwalsh.name/dw-content/html5-placeholder.php

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink
  4. Every solution i've tried works until the gravity form is submitted. If the validation triggers and requires more fields to be populated, all the input placeholders disappear and the labels reappear.

    It's really frustrating me as there should be a simple way to keep the placeholders in the input fields.

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink
  5. Can you post a link to a Gravity Form where this behaviour can be seen? Thanks

    Posted 11 years ago on Thursday July 5, 2012 | Permalink
  6. I'm not really in a good position to upload my project at the moment. However, i'm using the gravity form plugin, along with the functions.php code from this article: http://www.wpbeginner.com/wp-tutorials/how-to-add-placeholder-text-in-gravity-forms/

    I'd really appreciate it if you can take a look. I was using contact form 7, which natively supported placeholders, but i switched to gravity to make the experience for the client a lot more enjoyable.

    Sadly i *need* placeholders to work - they're in the designs that have been signed off.

    I'd really hate to be forced to switch back after purchasing a license for this.

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  7. Can you export the form you are working with and email it to chris@rocketgenius.com - include any additional code you're using to make this work. Without seeing your form it will be difficult to help you.

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  8. Okay, i've put the code online, and sent you a link to the page, along with the functions.php file to your email address.

    Eagerly, and excitedly, awaiting your reply!

    Posted 11 years ago on Sunday July 15, 2012 | Permalink
  9. Scott, I emailed you. I have a "jQuery is not defined" error after submitting an incomplete form. That's when the placeholder text goes missing. Please see the email.

    Posted 11 years ago on Tuesday July 17, 2012 | Permalink
  10. I've responded to your email. The issue wasn't the protocol related URLS.

    The following hook:

    add_action('gform_enqueue_scripts',"my_gform_enqueue_scripts", 10, 2);

    Seems to be injecting my jQuery scripts to the very top of wp_head();
    Obviously by doing that, it's executing before the Wordpress implementation of jQuery has even loaded.

    I've changed the hook priority below and above 10, but nothing happens. Is there a way to shift it's position in wp_head() to execute after jQuery has loaded?

    Posted 11 years ago on Wednesday July 18, 2012 | Permalink
  11. Scott, I replied to your email. Once we resolve this issue we can post the solution here.

    Posted 11 years ago on Wednesday July 18, 2012 | Permalink
  12. Mastal
    Member

    Until the gravity team adds this feature, I did a workaround really really ugly but that works for me:

    On field description i added some like this:

    This description will be shown.<span class="example">http://google.com</span>

    Add the CSS rule to hide it:

    .gform_wrapper .example {
        display: none;
    }

    Add this to functions.php, to make it works with ajax forms:

    add_filter('gform_pre_render', 'tuneUpElements');
    function tuneUpElements($form) {
        $script = 'tuneUpElements();';
    
        GFFormDisplay::add_init_script($form['id'], 'tuneUpElements', GFFormDisplay::ON_PAGE_RENDER, $script);
    
        return $form;
    }

    And finally this javascript function:

    $('.gfield').each(function(){
        if( $(this).find('.example').length != 0 ) {
            $(this).find('input').attr('placeholder',$(this).find('.example').text());
        }
    });

    As I said, Im not proud about this way to add placeholders, but is the best that i have found.

    Posted 11 years ago on Sunday August 26, 2012 | Permalink
  13. That's not a bad way of doing it. Thanks for posting your solution.

    Posted 11 years ago on Monday August 27, 2012 | Permalink