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.

Prepopulated, disabled fields empty when validation fails

  1. usableweb
    Member

    Greetings! I'm prepopulating a couple fields using the add_filter method described here:

    http://www.gravityhelp.com/documentation/page/Allow_field_to_be_populated_dynamically

    I was also using this technique to disable input:

    http://www.gravityhelp.com/forums/topic/make-a-readonly-field#post-7034

    This worked well, up until the point the form failed validation (let's say one of the required fields is left blank. When the screen refreshed to display the validation messages, the pre-populated fields were blank.

    This only happened when the input fields were disabled. My assumption is that the validation logic is not retaining the value attribute of disabled fields when the form is re-posted. I had to re-enable the fields by removing the 'disable' class again in order to make this work properly

    Would this perchance be an easy fix? Any suggestions?

    Thanks for the great plugin!

    Posted 12 years ago on Friday November 2, 2012 | Permalink
  2. I'm sorry your question was overlooked. I sent this off to the development team for their feedback.

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  3. When you disable an input, its value doesn't get posted with a form submission. That is why it is not retaining its value. Instead of marking it disabled, try marking it as read-only.
    Use the following snippet instead.
    http://pastie.org/5372225

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  4. usableweb
    Member

    Thanks a bunch - this worked great! I 'namespaced' the class name a bit to reduce the possibility of collision with other core/plugin CSS. For those searchers who are interested in the full/final fix:

    1) Inserted the following snippet in header.php between wp_head() call and closing head tag:

    <script type="text/javascript">
       jQuery(document).ready(function($){
          $(".gform_wrapper .gf_readonly input").prop('readonly',true);
       });
    </script>

    2) Then for prepopulated fields that are 'read only', on the Advanced tab, add the following CSS Class Name: gf_readonly

    Thanks Alex!

    Posted 12 years ago on Wednesday November 14, 2012 | Permalink

This topic has been resolved and has been closed to new replies.