* Purely an informative post for the community, no need for an Admin response *
I just spent a little while editing the code provided by the admin's on how to dynamically populate checkboxes so I could create a list of services from a custom taxonomy. It was pretty straight-forward but I just thought I'd post it incase it saves someone 20 minutes in the future.
All the best,
Andy
//Adds a filter to form id 3, change number 3 to your form ID.
add_filter("gform_pre_render_3", populate_checkbox);
add_filter("gform_admin_pre_render_3", populate_checkbox);
function populate_checkbox($form){
//Creating choices and inputs as empty arrays
$choices = array();
$inputs = array();
$categories= get_categories('taxonomy=services'); // change services to the name of your taxonomy
$i = 1; // we need a counter to create the field id
// loop through the array and push the results to the $choices and $inputs arrays
foreach ($categories as $category) {
// field_id identify's which element this is going to replace. Change 2 to whatever your field id should be
$field_id = "2.".$i;
array_push($choices, array("text" => $category->cat_name, "value" => $category->cat_name));
array_push($inputs, array("label" => $category->cat_name, "id" => $field_id));
$i++; // add 1 to the counter for the next loop
}
//Adding items to field id 2. Replace 2 with your actual field id. You can get the field id by looking at the input name in the markup.
foreach($form["fields"] as &$field){
//replace 2 with your checkbox field id
if($field["id"] == 2){
$field["choices"] = $choices;
$field["inputs"] = $inputs;
}
}
return $form;
}