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 input fields

  1. I use this http://www.gravityhelp.com/forums/topic/terms-and-conditions-text-record-in-form-entries-database#post-25225

    here: http://hardthaus.de/feinschmeckertermine/wintergemuse-und-beilagen-kochkurs/

    but I have more forms on this site where I would like to use this function... I tried to ad the code 2 times changing the ID of the form, but then I got an error? how must I write the code to have this function on more form?

    Posted 12 years ago on Friday December 21, 2012 | Permalink
  2. David Peralty

    If you want to use it multiple times, you need to change the function name as the function needs to be unique. Or you can test for the form ID and apply the same function to multiple form ID's.

    Posted 12 years ago on Friday December 21, 2012 | Permalink
  3. you can test for the form ID and apply the same function to multiple form ID's.

    How can I apply more form ID´s to one function? Can I write more filters and then the function? or how does it work...
    add_filter('gform_pre_render_2', 'add_readonly_script');
    add_filter('gform_pre_render_6', 'add_readonly_script');

    Posted 12 years ago on Friday December 21, 2012 | Permalink
  4. David Peralty

    First you take out the form qualification in the filter:

    add_filter('gform_pre_render', 'add_readonly_script');

    Then you test against ID's:

    if($form["id"] != 2 || $form["id"] != 3 )
           return $form;

    Does that help?

    Posted 12 years ago on Friday December 21, 2012 | Permalink
  5. I have no idear of php, so please point out my mistakes? it does not work with more than one form :(

    // Gravity Form Read only Input Fields - use ID of your form
    add_filter('gform_pre_render', 'add_readonly_script');
    if($form["id"] != 2 || $form["id"] != 3 || $form["id"] != 6 || $form["id"] != 7 || $form["id"] != 22 )
    	       return $form;
    function add_readonly_script($form){
        ?>
    
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery("li.gf_readonly input").attr("readonly","readonly");
            });
        </script>
    
        <?php
        return $form;
    }
    Posted 12 years ago on Sunday December 23, 2012 | Permalink
  6. Which forms are you trying to apply this to? My guess is that your logic is wrong in line 03 above. In plain language, not code, can you state on which form(s) you want this to apply?

    In the above, you are basically saying, "if form does not equal 2, or form does not equal 3 ..." - which will return the form, right off the bat, since form 2 does not equal form 3, and you have an OR condition (||). You will have to rewrite that statement.

    Posted 12 years ago on Sunday December 23, 2012 | Permalink
  7. I would like to ad this to five forms with following id´s: 2, 3, 6, 7 and 22

    Posted 12 years ago on Sunday December 23, 2012 | Permalink
  8. David Peralty

    Your logic is correct, but the IF statement goes inside of the function call. Basically, the if statement is saying if it isn't one of these then just exit and return the form normally, otherwise, continue to the lines below...

    Posted 12 years ago on Sunday December 23, 2012 | Permalink
  9. Just want to suggest using a switch to designate which form is to be use.

    switch($form['id'])
    {
         case 2:     Code here for Form 2
                          break;
         case 3:     Code here for Form 3
                          break;
         case 6:     Code here for Form 6
                          break;
         case 7:     Code here for Form 7
                          break;
         case 22:     Code here for Form 22
                          break;
    }

    It works well for Field IDs also.

    Posted 11 years ago on Friday February 8, 2013 | Permalink
  10. Thanks for that tip Drew.

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