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.

How to dynamically populate a checkbox field

  1. I have seen a few examples of how to do it for checkboxes on the forums but they all seem to create the checkboxes on the fly using the gform_pre_render hook. My situation seems to be a bit different as I already have the checkbox with all the fields created and all I want to do is to check the boxes based on the values in the database. The data is contained in the post meta and when I use the following code it checks only the first value encountered...

    add_filter('gform_field_value_postmeta_community_amenities', create_function("", '$value = populate_postmeta(\'community_amenities\'); return $value;' ));
    
    function populate_postmeta($meta_key){
    	$postID = '469';
    	$value = get_post_meta($postID, $meta_key, true);
    	return $value;
    }

    Any ideas on what am I doing wrong?

    Posted 8 years ago on Friday December 30, 2011 | Permalink
  2. So you don't want to dynamically populate the content of the checkbox (the actual data), you just want to dynamically pre-select which of the existing checkboxes should be automatically checked?

    Posted 8 years ago on Friday December 30, 2011 | Permalink
  3. Yes. Basically I have 2 forms, one where I allow the user to check the checkboxes that he needs and upon subimttal it creates a post where all the checkbox data gets saved as a post meta value. Then I have this second form that would allow them to edit their data.

    Posted 8 years ago on Friday December 30, 2011 | Permalink
  4. I am trying to find the right place to post this. Seems like every post has bits and pieces of what I am trying to accomplish. I have a checkbox list being populated by taxonomy's. Everything shows up perfect int he GF entries but it is not populating the preset taxonomy choices in my custom post type.

    Example

    I have a post type called "listing" with an attached taxonomy of "businesses" with lets say 5 choices of possible taxonomies. "Bands, DJs, Hotels, Restaurants, Barbers" If the user selects 3 out of the 5 and submits the form it seems to save the data in the entry but only checks one of the boxes. Which on the front end prevents it from showing up in each of the selected taxonomies.

    Is there away to force it to check off all that were selected?

    Thanks

    Posted 8 years ago on Thursday February 16, 2012 | Permalink
  5. Found a solution

    Add the below code to your functions.php file. Make sure to change the form ID 51 to what ever form that has your checkboxes.

    http://www.pastie.org/3391927

    Posted 8 years ago on Thursday February 16, 2012 | Permalink
  6. admin@clickcom.com
    Member

    Does anyone have an answer for antonv's origianl question? It seems like there is some confusion around the term 'populate' in this forum.

    I have a checkbox group with the 'Allow field to be populated dynamically' checked. I understand how hooks work, but I haven't been able to find any documentation on what to return in order to automatically check certain boxes.

    Posted 8 years ago on Wednesday March 28, 2012 | Permalink