I’ve looked through the forum and have seen something similar to my issue, but never quite the same. The closest that came to my issue was never resolved: https://support.advancedcustomfields.com/forums/topic/acf_form-id-not-being-set-from-args/
Anyway, here goes.
I have a frontend where multiple users are listed on a single page, each with their won acf_form. During validation, the values of the correct form are submitted, but the _acf_form and post_id values are always taken from the last form on the page. Here’s the simplified code:
<?php
foreach($users as $user) {
acf_form(array(
'id' => 'user-form-' . $user->ID,
'post_id' => 'user_' . $user->ID,
'fields' => array(
'firstname',
'lastname',
'email'
)
));
}
and then the verification hook:
function my_validate_value_email($valid, $value, $field, $input) {
$user_id = substr($_POST['post_id'], 5);
$user = get_user_by('email', $value);
return $user && $user->ID != $user_id ? __('Email already exists', 'text-domain') : $valid;
}
add_filter('acf/validate_value/name=email', 'my_validate_value_email', 10, 4);
Now when I view the page, the form IDs are all correct, and the data is pre-filled correctly. But when I click on “save” for the first user, then the form data that is submitted for verification is correct except for post_id = user_{last-user-id}, meaning every time I just try to save a user that is not the last user in the list, then I get the “email already exists” error.
I’m using ACF Pro 5.5.3 if that helps.