I have a page with several ACF forms to update user data. It’s basically a checklist where we’re gathering user data. With some of those forms I’d like to send an email the first time they’re submitted.
I’ve added an action to ‘acf/save_post’. I see in the forums how to have that fire only on specific posts. How do I change that so that it only fires on specific form submittals? Right now I’m checking if that field has a value and the next field in the list doesn’t have a value. I’m assuming there is a better way.
function specific_field_submittal_notification( $post_id ) {
$current_user = get_field_objects(get_current_user_id());
if ($current_user['field_1']['value'] && !$current_user["field_2"]["value"]){
//wp_mail code here...
}
}
add_action('acf/save_post' , 'specific_field_submittal_notification');
I ended up changing this to a pre-save filter (I needed to change some of the values) and I looked for specific custom fields and called my mail functions from there.
function custom_acf_pre_save_post($post_id) {
if($_POST['acf']['field_5a0dc6820fd89'] && ($_POST['acf']['field_5a0dc6820fd89'] != get_field('custom_field', $post_id)){
//wp_mail code here...
}
return $post_id;
}
add_filter('acf/pre_save_post' , 'custom_acf_pre_save_post', 10, 1);