Issue with auto-populating a Lookup field in a repeater

By: George Ciamita | Asked: 05/18/2024
ForumsCategory: How-toIssue with auto-populating a Lookup field in a repeater
George Ciamita asked 7 months ago
Hi everyone, I'm facing an issue with auto-populating repeater fields in Formidable Forms. I have a form (Form ID: 113) that includes a repeater section (Field ID: 3678) and several fields within this repeater. My goal is to duplicate an entry from the same form and populate all the fields within the repeater section. While the code successfully populates most of the fields, I'm encountering an issue. The repeater section contains two lookup fields. The first lookup field (Field ID: 3680) is being populated correctly, but the second lookup field (Field ID: 3681), which is dependent on the first, remains empty. The second lookup field is supposed to filter its options based on the value of the first lookup field. I would appreciate any insights or solutions you might have or suggest. Thank you in advance for your help! Here is the code I use:  add_filter('frm_setup_new_fields_vars', 'frm_auto_populate_repeating_fields', 20, 2); function frm_auto_populate_repeating_fields($values, $field) { // Mapping for each repeater field $repeaters = [ 3678 => [ 'form_id' => 113, 'field_mappings' => [ 3679, 3680, 3681, 3682, 3683, 3684, 3686, 3687, 3689, 3690, 3691, 3692, 3694, 3695, 3698, 3699, 3700, 3703 ] ], // Other repeater fields and their mappings 36333 => [ 'form_id' => 113, 'field_mappings' => [ 3992, ] ] ]; if (array_key_exists($field->id, $repeaters)) { if (!isset($_POST['item_meta'][$field->id])) { $original_entry_id = isset($_GET['pass_entry']) ? sanitize_text_field($_GET['pass_entry']) : 0; if ($original_entry_id) { $original_entry = FrmEntry::getOne($original_entry_id, true); if ($original_entry) { $repeater_field_id = $field->id; $repeater_values = isset($original_entry->metas[$repeater_field_id]) ? $original_entry->metas[$repeater_field_id] : array(); $values['value'] = array('form' => $repeaters[$repeater_field_id]['form_id'], 'row_ids' => array()); foreach ($repeater_values as $repeater_entry_id) { $repeater_entry = FrmEntry::getOne($repeater_entry_id, true); if ($repeater_entry) { // Populate the repeater fields $values['value']['row_ids'][] = $repeater_entry_id; $values['value'][$repeater_entry_id] = array(); foreach ($repeaters[$repeater_field_id]['field_mappings'] as $field_id) { $values['value'][$repeater_entry_id][$field_id] = $repeater_entry->metas[$field_id] ?? ''; } } } } } } } return $values; }

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right