Skip Navigation

[Resolved] Validate that two fields match – show error message if not

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Author
Posts
#2278717
Screen Shot 2022-01-28 at 12.53.24 PM.png

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?

#2279247

Christopher Amirian
Supporter

Languages: English (English )

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.

#2281939

My issue is resolved now. Thank you!