Hello,
I would like to be able to read a field value before saving the form to apply it in another field in an acf_form
I have a “starting_date” date field and an “ending_date” date field for events.
In case “ending_date” is emplty, I would like to copy “starting_date” value in “ending_date” field.
I’m pretty sure I’ll get a solution with an “update_value” filter function. I can set a value to a field, but I didn’t found any solution in documentation to get a field value before saving in a acf_form.
Do you have any clue by chance ?
Frédéric
it was easy in fact, even if getting field value is easier after the save of the post 🙂
function argu19_set_ending_date_if_empty( $post_id ) {
if ( !isset($_POST['acf']['field_5bd0266e9f955']) ) :
$value = get_field('event_startingdate');
update_field('event_endingdate', $value);
endif;
}
// Apply to all fields.
add_filter('acf/save_post', 'argu19_set_ending_date_if_empty', 10, 3);
Thank you for this thread!
The strangest thing –
I can see the field updated only after I refresh the page….
Any Idea?