Choices Callback + Parent Option gets removed from by validation.
-
Using hook
um_before_save_filter_submitted
orum_before_save_registration_details
has wrong$submitted
values due to I believevalidate_fields_values()
In more details I have used a plugin that give user groups and I use the groups structure to populated two select form. This is a simplified form structure I have:
'company' => array ( 'type' => 'select', 'metakey' => 'company', 'title' => 'Company', 'custom_dropdown_options_source' => 'getCompanies', ), 'sub_company' => array ( 'type' => 'select', 'metakey' => 'sub_company', 'title' => 'Sub Company', 'custom_dropdown_options_source' => 'getSubsidies', 'parent_dropdown_relationship' => 'company', ),
Code to fill the selects:
function termsToArray($terms) { $output = array(); foreach ($terms as $term) { $output[$term->term_id] = html_entity_decode($term->name); } return $output; } // Function to extract main Companies function getCompanies() { $terms = get_terms( 'user-group', array( 'hide_empty' => false, 'orderby' => 'term_order', 'order' => 'ASC', 'parent' => 0 )); return termsToArray($terms); } // Function to extract Subsidies for a given Companie function getSubsidies() { $parent_id = $_POST['parent_option']; $parent_term = get_term($parent_id, 'user-group'); $terms = get_terms( 'user-group', array( 'hide_empty' => false, 'orderby' => 'term_order', 'order' => 'ASC', 'parent' => $parent_id )); $terms = array_merge(array($parent_term), $terms); return termsToArray($terms); }
This part works nice. Data gets submitted, values come back as term ids. But when
validate_fields_values()
gets called on hookum_before_save_filter_submitted
there is no way for the custom functiongetSubsidies()
to respond without a$_POST
andsub_company
gets removed from$submitted
values.Now this creates multiple problems for me.
1. {submitted_registration} will always print “Sub Company: (empty)”
2. Will need to convert term_id to name for {submitted_registration} and I haven’t found a hook for that yet.
3. I needed to assign a user-group term to each new user. I was only able to do this because onum_before_save_filter_submitted
I got the full$form_submitted_data
.
- The topic ‘Choices Callback + Parent Option gets removed from by validation.’ is closed to new replies.