I’m using acf_form
to create a registration form and all works well. I’m hooking acf/save_post
and using wp_create_user
as recommended. However, if a user with the requested user name exists, wp_create_user
returns an error. This is expected and correct.
* How can I display this error in the front end? I can’t just echo
it, as the standard function of acf_form
is that the page is refreshed after submission.
* If the submission fails, then I use return
to redirect the visitor. How can I retain the values which the user entered in the registration form if the submission fails?
Should I be using $_SESSION
variables?
The best way to do this is to have add an acf/validate_value filter https://www.advancedcustomfields.com/resources/acf-validate_value/ to the field you’re using to determine what user to add.
Ah, so catch it before it even tries to submit?
Yes, exactly. You can then have ACF show the error message, “This user already exists” or something like that.
Great idea, thanks for the tip John.