Hi Hyperarts,
Thanks for the reply.
I am actually running two acf_forms in two separate divs. Each Div shows/hides when the user clicks on a link.
Form_A lets the user input all of their information.
Form_B lets the users select certain printing preferences before generating a PDF of the information from Form_A.
The problem I am running into, is that if the user saves Form_B before saving Form_A, any changes or information made in Form_A are lost. Since they are not actually leaving the page though, the normal acf warning (which would be fine for my purposes right now) does not pop up.
I would like to have some sort of warning when the user clicks on the link to show Form_B, but hasn’t yet saved Form_A, it stops them/reminds them to save, etc.
Does that clarify the situation better?
Jess
Hi there,
I am actually having the opposite problem. I have a specific link which shows/hides a div. I want the navigation warning to pop up if the user clicks on the div as a way to remind them to save their work.
Is there a way to use the existing javascript to do this?
Thanks!
You’re Brilliant @hube2! This fixed it!
Here is a simplified version of how the code worked:
function update_sub_fields() {
global $wpdb; //declare using a global variable
$import_post_id = get_field('import_post'); //get the id of the post we are importing data from
if( have_rows('repeater_field_name') ): //start the repeater loop
while( have_rows('repeater_field_name') ): the_row();
$unique_id = get_sub_field('unique_id_field'); //get the unique id
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM {$wpdb->prefix}postmeta
WHERE post_id = %s
AND meta_key LIKE %s
AND meta_value = %s
",
$import_post_id, //only look at meta-values that match the post we are importing from
'import_repeater_field_%_unique_id_field', // meta_name: $ParentName_$RowNumber_$ChildName
$unique_id // meta_value: to match our unique id
));
if( $rows ){
foreach( $rows as $row ){
preg_match('_([0-9]+)_', $row->meta_key, $matches);
$r = $matches[0];
$import_rows = get_field('import_repeater_field', $import_post_id);
$current_import_row = $import_rows[$r];
$sub_field_to_import = $current_import_row['sub_field_to_import'];
update_sub_field('new_field_to_update', $sub_field_to_import);
} //End foreach
} //End if
endwhile; //end loop
endif;
}
add_action( 'acf/imput/form_data', 'update_sub_fields', 10, 1);
I hope this helps anyone else who might be looking to import data from one repeater field to another!
Jess
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.