diff --git a/includes/gravity-forms.php b/includes/gravity-forms.php index 1c2b3dd..cce2272 100644 --- a/includes/gravity-forms.php +++ b/includes/gravity-forms.php @@ -1,12 +1,16 @@ false, // Include empty terms )); - // Prepare choices array for the select field - $choices = array(); - foreach ($terms as $term) { - $choices[] = array( - 'text' => $term->name, - 'value' => $term->term_id, - ); - } - - // Find the select field by ID + // Find the checkbox field by ID foreach ($form['fields'] as &$field) { if ($field->id == $field_id) { - // Update choices for the select field + // Prepare choices and inputs array for checkboxes + $choices = array(); + $inputs = array(); + $index = 1; + + foreach ($terms as $term) { + $choices[] = array( + 'text' => $term->name, + 'value' => $term->name, // Use term name as value for display + 'isSelected' => false, + ); + + // For checkboxes, each choice needs a corresponding input + $inputs[] = array( + 'id' => $field->id . '.' . $index, + 'label' => $term->name, + 'name' => '', + ); + + $index++; + } + + // Update choices and inputs for the checkbox field $field->choices = $choices; + $field->inputs = $inputs; + + // Ensure the field is not marked as administrative only + $field->adminOnly = false; + + break; } }