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;
}
Please login or Register to submit your answer