Skip to Content Skip to Menu

Cross-validation

  • autobahn
  • autobahn
  • OFFLINE
  • Posts: 202
  • Thanks: 38
  • Karma: 4
4 years 1 week ago #321431 by autobahn
Cross-validation was created by autobahn
Is there a way to cross-validate input fields on a profile/registration form?

For example, if I have two input fields Field A and Field B can I check the following:

1. If Field A = "None" Then Field B MUST be = "None"
OR
2. If Field B <> "None" Then Field A MUST be = "None"

i.e. both fields must be = "None" or neither field can be = "None".

The fields in question are both dropdown lists.

Thank you

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48548
  • Thanks: 8290
  • Karma: 1445
4 years 6 days ago - 4 years 6 days ago #321444 by krileon
Replied by krileon on topic Cross-validation
Yes, using CB Code Field and its Code Validation. This lets you validate a field using your own custom PHP. Example as follows on how to do this.

Code Validation: Enable
Code (PHP):
Code:
if ( '[FIELD_A_NAME]' != 'None' ) { return true; } return ( '[value]' == 'None' );
Ajax Validation: Enable
Additional Fields: Field A

Be sure to replace FIELD_A_NAME with the actual name of Field A field. The above would be applied to Field B and covers case 1. It first checks if Field A is None and if it isn't the validation is skipped and if it is then it also checks if Field B is also set to None .For case 2 you'd need to right a similar validation rule for Field A.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 4 years 6 days ago by krileon.

Please Log in or Create an account to join the conversation.

  • autobahn
  • autobahn
  • OFFLINE
  • Posts: 202
  • Thanks: 38
  • Karma: 4
4 years 6 days ago #321447 by autobahn
Replied by autobahn on topic Cross-validation
Thank you for such a quick reply.

This is excellent and I will give it a try.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum