Hello,
I'm using last version of Gravity Forms (1.4.3.1) and it was very easy to set up a complex and lengthy form. The purpose of the form is to create a custom post type. This part is working thanks to hints I found on this forum. I'm trying now to set up checkboxes that will populate custom taxonomies when values are checked.
More details here:
- List A of checkboxes (id=24) for custom taxonomy 'access'
- List B of checkboxes (id=25) for custom taxonomy 'services'
Here is my PHP code:
add_filter("gform_post_submission", "insert_custom_taxonomies",10,2);
function insert_custom_taxonomies($entry, $form){
if($form["id"] !=1)
return;
$post_id = $entry["post_id"];
$choices_services = "";
$choices_access = "";
foreach($form["fields"] as &$field){
if($field["id"] == 25){
foreach($field["choices"] as $choice){
$field_value = !empty($choice["value"]) || $field["enableChoiceValue"] ? $choice["value"] : $choice["text"];
$choices_services.= $field_value.',';
}
}
if($field["id"] == 24){
foreach($field["choices"] as $choice){
$field_value = !empty($choice["value"]) || $field["enableChoiceValue"] ? $choice["value"] : $choice["text"];
$choices_access.= $field_value.',';
}
}
}
wp_set_object_terms($post_id, explode(",", $choices_service), "service");
wp_set_object_terms($post_id, explode(",", $choices_access), "access");
}
This does not work as my vars 'choices_access' and 'choices_services' are empty before calling 'wp_set_object_terms'.
I've tried var_dump($choice) for debugging purpose in "foreach" loop, but even if I check a checkbox in the form, "IsSelected" property is set to "false" after submission.
- Am I using a wrong hook to populate my taxonomies? I've tried 'gform_pre_submission' hook, without any success.
- Is there a way to know if a checkbox was checked before hitting submission button?
Anyone can help?
Thanks!
Vincent