Using Query Validation

6 years 8 months ago #296424 by cliffvt
Using Query Validation was created by cliffvt
Guys, I have a Integer field which a user can edit on thier profile. I don't want that number to smaller than 1 or larger than the value of another field - been scratching my head for days on how to achieve that - anyway you can help me with some ideas?

So the fields are:
  • Text field 1 - cb_totalpax (yes unfortunatley this is a text field, I guess I could change it to an integrer field not sure if CB can do that automatically?)
  • Integer field 2 - cb_uktfrpaxout
So the validation whilst user is entering or updating cb_uktfrpaxout should be something like if user input in [cb_uktfrpaxout] < 1 or > [cb_totalpax]
then error message

Anyway this can be done?

I tried using Query Validation but I guess I am not familiar with the syntax etc of how to structure the query :(

Thanks

Cliff

Please Log in to join the conversation.

6 years 8 months ago #296432 by krileon
Replied by krileon on topic Using Query Validation
Integer fields have built in minimum and maximum value parameters (under Parameters > Validation). For the minimum value you'd set it to 1 and for the maximum value leave as unlimited. Next you'll either need to use CB Code Field or CB Query Field and their validation parameters to have custom validation. For a code field it should be as simple as follows.

Code Validation: Enabled
Code:
return ( (int) '[value]' <= (int) '[cb_totalpax]' );
Ajax Validation: Enabled


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.

Please Log in to join the conversation.

6 years 8 months ago #296433 by cliffvt
Replied by cliffvt on topic Using Query Validation
So i did this and the result was a browser error saying:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'return ( (int) '5' <= (int) '2' )' at line 1

I'm not sure what the syntax error is - can you help? :) Sorry...

Please Log in to join the conversation.

6 years 8 months ago #296435 by krileon
Replied by krileon on topic Using Query Validation
You're trying to use CB Code Field validation in CB Query Field. My above example is for CB Code Field validation as it's not necessary to do another database query for this.


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.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.191 seconds

Facebook Twitter LinkedIn