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.

dynamically populate field using variable

  1. les112
    Member

    I want to dynamically populate the category field using the parameter categoryid. In an earlier post by Kevin there was the following code snippet

    <?php
    add_filter("gform_field_value_categoryid", "populate_categoryid");
    function populate_categoryid($value){
    return  "55" ;
    }
    ?>

    where "55" is the explicit value for the parameter categoryid. This works.
    But I don't wan't to enter the explicit value by hand but rather use the variable $category_id, which has been calculated earlier in the theme function.
    What modification to the above code snippet needs to be done to use the variable $category_id rather than the explicit value "55".

    Posted 13 years ago on Sunday March 27, 2011 | Permalink
  2. I used this, it's pretty much the same but you just use whatever WP function to pull out the value; in my case, a post title.

    function populate_title(){
            $UTitle_value = get_the_title();
        return $UTitle_value;
        }
    add_filter("gform_field_value_UTitle", "populate_title");

    I guess you've done it already, but you'll need to create an input, set it so it can be populated dynamically, then give it the parameter name you specified in the function; in my case UTitle.

    Multiple categories, category child / parent etc. could cause you some problems.

    Posted 13 years ago on Monday March 28, 2011 | Permalink
  3. les112
    Member

    Thanks teabag for your reply. Sorry about the time delay but I am in Australia with different timezone.
    I couldn't get your code to work..
    The following worked. The closest I got to getting the page title, which I also want, was the page name using get_query_var('category_name')

    add_filter("gform_field_value_categoryid", "populate_categoryid");
    function populate_categoryid($value){
    return get_query_var('cat');
    }
    Posted 13 years ago on Tuesday March 29, 2011 | Permalink