Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 25th)

form validation over multiple fields

5 years 2 weeks ago #315639 by Allwinds007
form validation over multiple fields was created by Allwinds007
I really would appreciate if there is a solution to my idea ;-)

Situation: I have a register and profilings edit form with 2 integer fields, that can take values between 0 and 100.

What I want to do:
It should not be possible to register or update:
- it not at least one of those fields have a value higher then 0

Can You please give me a hint, how this can be realised?

I tried an additional field, that sums up the values of the two fields, and is checked to be higher then 0 - but this didn't work before saving the data to the database.

Thank you very much

best regards Thomas

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48609
  • Thanks: 8300
  • Karma: 1446
5 years 2 weeks ago #315651 by krileon
Replied by krileon on topic form validation over multiple fields
That's actually just now doable. You'll need to update to the latest CB build releases today. Next you'll need CB Code Field latest build also released today. Once done edit your integer fields and under Integrations > CB Code Field enable Code Validation. Now you should be able to add custom PHP based validation to validate your fields, but you'll have to use the new Additional Fields feature so that Field A is sent the value of Field B allowing you to do an either/or check. Example as follows.

Code Validation: Enable
Code (PHP):
Code:
return ( ( (int) '[cb_field1]' > 0 ) || ( (int) '[cb_field2]' > 0 ) );
Ajax Validation: Enable
Additional Fields: cb_field2

The above for example would be added to cb_field1, which would also be sent the value of cb_field2 allowing you to check the value of cb_field2 in addition to cb_field1. Be sure to replace cb_field1 and cb_field2 with the actual names of your fields. When adding this to cb_field2 you just need to change "Additional Fields" to cb_field1.


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 or Create an account to join the conversation.

5 years 2 weeks ago #315663 by Allwinds007
Replied by Allwinds007 on topic form validation over multiple fields
Thank's. I installed all latest releases (espacially Code Field and Community Builder) and tried as you described, but the result when validating the field behaves somehow strange:

- values 0 return "ok"
- values >0 return false....

I can change between

return ( ( (int) '[cb_field1]' < 0 ) || ( (int) '[cb_field2]' < 0 ) );

and

return ( ( (int) '[cb_field1]' > 0 ) || ( (int) '[cb_field2]' > 0 ) );

without any effect....

do you have an idea what's going wrong?
Attachments:

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48609
  • Thanks: 8300
  • Karma: 1446
5 years 1 week ago #315691 by krileon
Replied by krileon on topic form validation over multiple fields
You should be using the below code.

Code:
return ( ( (int) '[cb_field1]' > 0 ) || ( (int) '[cb_field2]' > 0 ) );

But again you need to replace cb_field1 and cb_field2 with the actual names of your fields. Do not leave them as cb_field1 and cb_field2 as those fields do not exist in your install. The field should validate if either of the supplied fields values are greater than 0. I suppose you could also do the sum approach again as well with the below.

Code:
return ( ( (int) '[cb_field1]' + (int) '[cb_field2]' ) > 0 );


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 or Create an account to join the conversation.

5 years 1 week ago #315693 by Allwinds007
Replied by Allwinds007 on topic form validation over multiple fields
thank's. That's clear - I did replace the field-names with my custom field-names (i.e. cb_haus2 and cb_garten2); and something is evaluated, but not the right way ;-(

I also try your other code-line, but with the same result.

Could it be, that there is a code-line-mistake in the plugin, where the values are evaluated?

Sorry, for bothering again.

It would be really helpful if we could find the solution

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48609
  • Thanks: 8300
  • Karma: 1446
5 years 1 week ago #315699 by krileon
Replied by krileon on topic form validation over multiple fields
It depends entirely on where this is being added to. If it's being added to cb_field1 then replace [cb_field1] with [value]. If it's added to cb_field2 then replace [cb_field2] with [value]. Try the below for example

cb_field1
Code:
return ( ( (int) '[value]' > 0 ) || ( (int) '[cb_field2]' > 0 ) );

cb_field2
Code:
return ( ( (int) '[cb_field1]' > 0 ) || ( (int) '[value]' > 0 ) );


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum