Hello,
I’m looking to add some custom validation for a frontend (acf_form()) form input.
The form input needs to make an ajax request to validate it’s value.
What’s the best way to do this in an ACF supported way?
– – –
I’ve tried to add an event listener to the form submit, and I can prevent it from submitting to run my own validation, but then I can’t get the form to submit again for some reason.
I’ve tried putting a listener onto the input itself, but then it’s a race against the user and ACFs own form submission validation.
I’ve tried to go the PHP route with the validation filter hook, but wp_die() is probably the lamest way to show an error message that I can possibly imagine.
I’ve tried taking a look at the JS docs, but sometimes their documentation isn’t always clear about what events do, what is given to them, or how to use them. It also doesn’t help that the ACF Pro input.js is minified, it doesn’t seem like it ships with any kind of unminified version either – makes it difficult to jump into the source to try and find a solution.
– – –
Ideally, I would like to return a validation error in a similar fashion to what ACF already does. Any suggestions on how I can accomplish this?