[SOLVED] Code field validation

3 years 6 months ago #321145 by krileon
Replied by krileon on topic Code field validation
If you return true the validation passed. If you return false the validation failed. Be sure to keep that in mind when supplying your custom validation code.


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.

3 years 5 months ago - 3 years 5 months ago #321187 by ericmuc
Replied by ericmuc on topic Code field validation
Hi,

Hereto I have a little further question for a situation, where I have two scenarios:

I need a double validation for a situation, where 1) [cb_cv_date_until] is empty and the second validation where 2) [cb_cv_date_until] is not empty (because the user could fill something in [cb_cv_date_until] before he added to [cb_cv_date_from]

So I would like to use this lines of code (serial, not nested) in the CB Code Field:
if ( ( '[cb_cv_date_until]' == "" ) && ( strtotime ( '[value]' ) < strtotime( 'now' ) ) ) return true;
if ( ( '[cb_cv_date_until]' !== "") && ( strtotime ( '[value]' ) < strtotime( [cb_cv_date_until] ) ) ) return true; 

Can I do these different situation with procedure? (The additional field at [cb_cv_date_from] is set to [cb_cv_date_until])

I missed the validation of the second line. That don't work.

If I have once this in place, I can go further alone for all other validations. Here I need a feedback to the general procedure with multiple validations. So I would like to ask you, whether you can give a short hint hereto again.

Thanks, best regards
Eric

Please Log in to join the conversation.

3 years 5 months ago #321192 by krileon
Replied by krileon on topic Code field validation
You can put as many validation rules as you like in your code. Just return true if validation passed or return false if it failed. This is all just standard PHP except with support for inline substitutions. If you need additional field values sent to the validation be sure you select those fields in the "Additional Fields" parameter below "Ajax Validation". My example in my reply below already shows multiple validation rules in a single usage.

www.joomlapolis.com/forum/255-developer-members-support/242953-code-field-validation?start=12#321132


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.

3 years 5 months ago #321195 by ericmuc
Replied by ericmuc on topic Code field validation
Hi,
Thanks, understand, now I got it working.

Only for the forum members to have a further working sample:
if ( ( '[date_2]' == "" ) && ( strtotime ( '[value]' ) < strtotime( 'now' ) ) ) return true;
if ( ( '[date_2]' !== "") && ( strtotime ( '[value]' ) < strtotime( '[date_2]' ) ) ) return true; 

This is the validation code field date_1 (add to CB Code Field, additinal field is date_2, ajax validation = on)

In this manner multiple validations line by line can be used.

Thanks, best regards
Eric
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.202 seconds

Facebook Twitter LinkedIn