Home › Toolset Professional Support › [Resolved] Validate that two fields match – show error message if not
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
This topic contains 2 replies, has 2 voices.
Last updated by karenZ 3 years, 6 months ago.
Assisted by: Christopher Amirian.
Hello,
I'm looking for code I can add to validate that two custom fields match. If they do not match an error message should display. I want to use this for my Email and Confirm Email field to ensure that the same email is submitted in both fields.
I found this support article which uses a code to validate two password fields:
https://toolset.com/forums/topic/how-to-show-an-error-if-the-passwords-do-not-match/
I followed the steps by adding this snippet to my Settings > Custom Code, I changed the ID to match my form ID, then I changed the two fields to match my field slugs. I then activated the custom code.
But the code is not working on my site. Any ideas what I'm doing wrong or how to use something similar to achieve this type of validation between two fields?
Hi there,
I am not sure that it is possible to do that 100%, but I do see an issue with the code that you shared:
In the
$errors['pass2']
I guess that you do not have any fields with the slug of 'pass2'.
You need to make sure that you provide a valid field slug there, to show the error below that specific field.
Also please make sure that your form does have the Form Messages field:
hidden link
See if it helps.
Thanks.
My issue is resolved now. Thank you!