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.

Read Only

  1. Aejandro
    Member

    Hello:

    I am trying to make a field "read only". I am following these documentation instructions: http://www.gravityhelp.com/forums/topic/terms-and-conditions-text-record-in-form-entries-database#post-25225

    ... but it does not work for me.

    My theme features a custom_functions.php file, so I am adding the given code there. (In fact, when I add the code to the functions.php file the theme get broken.)

    I input the form id properly as indicated.

    I have also added the gf_readonly to the field's class name.

    Is anything I have to double check?

    Here you have a link to my site: http://goo.gl/m68vW

    Thank you!

    Posted 11 years ago on Thursday February 7, 2013 | Permalink
  2. I see the script in the source:

    [js]
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery("li.gf_readonly textarea").attr("readonly","readonly");
            });
        </script>

    But I don't see the 'gf_readonly' class applied to any form fields. Can you view the source of that page and let me know which field has the gf_readonly class?

    Posted 11 years ago on Friday February 8, 2013 | Permalink
  3. Aejandro
    Member

    Sorry, because it was not ready, I did not put the field.

    Now it is there. Is the first field named TOUR (id: 33)

    Thank you

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  4. Looking at your form, your only textarea is field 24 (input_24) and that does not have a class of gf_readonly. However, your script is only targetting textareas with a class of gf_readonly. Field 33 is just 'text' not 'textarea'. If you change the one line in your script to this, it will work:

    jQuery("li.gf_readonly input").attr("readonly","readonly");
    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  5. Aejandro
    Member

    It is working now!!

    Please, last question: what if more than one form is needed to be filtered?

    This code is only for one form:

    // update '1' to the ID of your form
    add_filter('gform_pre_render_1', 'add_readonly_script');
    function add_readonly_script($form){
        ?>
    
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery("li.gf_readonly textarea").attr("readonly","readonly");
            });
        </script>
    
        <?php
        return $form;
    }

    Is it possible to filter more forms?

    Thank you

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  6. Duplicate only this line in your functions.php, once for each form. Change the form ID in the filter:

    // this will apply to form 1
    add_filter('gform_pre_render_1', 'add_readonly_script');
    
    // this will apply to form 6
    add_filter('gform_pre_render_6', 'add_readonly_script');
    
    // this will apply to all forms
    add_filter('gform_pre_render', 'add_readonly_script');

    No need to duplicate the function, just the "add_filter" line.

    Posted 11 years ago on Saturday February 9, 2013 | Permalink