Hi,
I am trying to make a custom registration form that uses ACF forms for custom fields (that can be defined by the client via the ACF interface). The few fields that are mandatory for this form are the email, password, and new member’s full name.
I registered a frontend form like this:
acf_register_form([
'id' => 'new-member',
'post_id' => 'new_user',
'form' => false,
'field_groups'=> ['group_1'],
'honeypot' => true,
]);
I then built my custom HTML form as follows (please keep in mind that I stripped a lot of code for legibility):
<form method="post">
<input type="email" class="input" name="email" value="" id="email" />
<?php acf_form( 'new-member' ); ?>
<button type="submit"><?php _e( 'Register' ); ?></button>
</form>
I will use the acf/pre_save_post
hook to modify the post_id to be user_ID (once I create the user) but ACF doesn’t seem to have a hook to use for custom validation.
I managed to add some custom errors using acf/validate_save_post
and the acf_add_validation_error() function but when a user submits and the values aren’t valid they are redirected to a “Validation failed” page instead of going back on the registration page with validation errors at the top of the form.
Is there a way to validate fields and show the errors on the form instead of this middle page?