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.

Populate hidden field with PHP multiple times

  1. Bryan K
    Member

    Hello,

    I have a form inside of the loop in a template so it shows up multiple times on a page, so I need to somehow distinguish which form was submitted in the entry information. After poking around on the forum I've come up with this. Sorry it's probably terrible – I'm not super great at PHP:

    <?php
    add_filter("gform_field_value_book", "populate_book");
    function populate_book($value){
       return get_the_title();
    }
    gravity_form(2, true, true);
    ?>

    Which prepopulates a hidden field called book with the title of the post the form is part of. It works like a charm until the second post on the page, where there's a fatal PHP error that the populate_book function has already been defined.

    There must be a way to do this, right? Am I going at it the wrong way?

    Thanks so much for any help.

    Posted 14 years ago on Thursday April 21, 2011 | Permalink
  2. Try putting that filter in your themes functions.php file and not in your loop.

    Posted 14 years ago on Thursday April 21, 2011 | Permalink
  3. Bryan K
    Member

    Oh dear. Yup, that's all it took. Thanks! I really should have tried that. :)

    One other question as long as I'm asking: Is there a way to enable AJAX on the gravity_form(2, true, true); thing? I've tried looking around and haven't been able to find that either.

    Posted 14 years ago on Thursday April 21, 2011 | Permalink
  4. Yes, you can enable AJAX using the function call. It is discussed int he documentation area for the function call here:

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

    Posted 14 years ago on Thursday April 21, 2011 | Permalink