Hello,
Thanks for the feedback!
I’m glad to hear that you enjoy ACF Extended ??
What you’re describing is the normal Form behavior, as the form name
is the real unique identifier. If you render the same form multiple time on the same page without Redirect Action, all of them will display the success message, because the page can only distinguish them by their name
.
You can however bypass that logic using the acfe/form/load
hook (See documentation), and display the success message only if the $form['my_data']
correspond with the form that has been submitted using the acfe_is_form_success()
helper (See documentation).
Here is a usage example:
add_filter('acfe/form/load/form=my-form', 'my_form_load', 10, 2);
function my_form_load($form, $post_id){
// get the updated message from the UI
$updated_message = $form['updated_message'];
// disable the sucess message for now
$form['updated_message'] = false;
// check if the form has been submitted
if(acfe_is_form_success($form['name'])){
// get the submitted form arguments
$success_form = acfe_form_decrypt_args();
// get 'my_data' from the current form & the submitted form
$form_data = acf_maybe_get($form, 'my_data');
$success_form_data = acf_maybe_get($success_form, 'my_data');
// check that the submitted form has the same 'my_data'
if($form_data && $success_form_data === $form_data){
// re-assign the updated message on the current form
$form['updated_message'] = $updated_message;
}
}
// return
return $form;
}
Front-end PHP code:
acfe_form(array(
'name' => 'my-form',
'my_data' => '1'
));
acfe_form(array(
'name' => 'my-form',
'my_data' => '2'
));
acfe_form(array(
'name' => 'my-form',
'my_data' => '3'
));
Video demo of the result.
Hope it helps!
Have a nice day!
Regards.