After auto-populating a repeater, changes I make inside the repeater fields afterwards are not saved except for the auto-populated fields.

By: Bright Madire | Asked: 10/25/2023
ForumsCategory: General questionsAfter auto-populating a repeater, changes I make inside the repeater fields afterwards are not saved except for the auto-populated fields.
Bright Madire asked 6 months ago

Hi everyone. I would appreciate your help on a certain issue which I have. After auto-populating a repeater, changes I make inside the repeater fields afterwards are not saved except for the auto-populated fields. I am using the code below to auto-populate:  

 

add_filter('frm_setup_new_fields_vars', 'frm_auto_populate_repeating_fields', 20, 2);
function frm_auto_populate_repeating_fields( $values, $field ) {
if ( $field->id == 331 && isset($_GET['request']) && $_GET['frm_page'] != 2 ) {
$source_entry_id = intval($_GET['request']);

 

$url = 'https://mysite.com/wp-json/frm/v2/entries/'.$source_entry_id;
$entryData = getRequest($url);

 

$entryArray = json_decode($entryData, TRUE);
$procuredItems = $entryArray['meta']['procured_items'];

 

$first_field = 320;
$second_field = 323;
$third_field = 322;

 

$values[ 'value' ] = array(
'form' => '10',
'row_ids' => array( implode(', ', range(0, count($entryArray['meta']['procured_items']) - 2)) ),
);

 

$i = 1;
foreach($procuredItems as $key=>$value) {
if ($key != "form"){
 
$title = $value['procured_item_name'];
$quantity = $value['procured_item_quantity'];
$desc = $value['procured_item_description'];

 

$values[ 'value' ][$i-1] = array( 0 => '', $first_field => $value['procured_item_name'], $second_field => $value['procured_item_quantity'], $third_field => $value['procured_item_description'] );

 

$i += 1;
}
}
 
}
return $values;
}

Attached is an image of the form showing other fields I would like to fill manually but they're being saved as empty even after I enter something!

Attachments
1 Answers
Best Answer
Bright Madire answered 6 months ago
Updating the if statement to the one below helped to stop the continuous auto-populating. if ( $field->id == 331 && isset($_GET['request']) && !isset($_POST['item_meta'][331]) )  

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