Hey all ... just wondering if I'm encountering a bug or not with gform_pre_render.
Using the following gform_pre_render filter to populate checkboxes:
add_filter("gform_pre_render_6", 'selected_location_checkboxes');
add_filter("gform_admin_pre_render_6", 'selected_location_checkboxes');
function selected_location_checkboxes($form){
global $current_user;
get_currentuserinfo();
$choices = array();
$inputs = array();
$args = array( 'hide_empty' => 0, 'taxonomy'=> 'location'); // custom taxonomy
$categories = get_categories($args);
array_push($choices, array("text" => 'All/None', "value" => '', "isSelected" => false));
array_push($inputs, array("label" => 'All/None', "id" => 'selectAllLocations'));
$i = 1;
foreach ($categories as $category) {
$field_id = "17.".$i;
array_push($choices, array("text" => $category->cat_name, "value" => $category->term_id, "isSelected" => (is_object_in_term( $current_user->ID, 'location', $category ) ) ? true : false ));
array_push($inputs, array("label" => $category->cat_name, "id" => $field_id));
$i++;
}
foreach($form["fields"] as &$field){
if($field["id"] == 17){
$field["choices"] = $choices;
$field["inputs"] = $inputs;
}
}
return $form;
}
As can be seen I'm attempting to add an initial checkbox with All/None as the text and no value and not selected.
It gets output as a checkbox on the front end however for some reason it is always marked as "checked". It's also automatically given an id of "choice_17_1" and NOT "selectAllLocations" as I need.
I'm trying to output a checkbox that can be used to select/deselect all other checkboxes on this field and need one checkbox that is not by default selected and also with a id of my choosing.
Anyone know if this is a bug or am I missing something? Anyone done this before?
Thanks
Scott