[SOLVED] Code field validation

3 years 6 months ago #320789 by ericmuc
Replied by ericmuc on topic Code field validation
Hi,

Ok, thanks. I need a special text for the error message for that field, because the date must be greater than another date and may not be greater than today. I understand, that this is not possible at the moment? I can only use ONE error message for all code validations?

Ok, I can wait on the update, just to understand, how it is at the moment.

Thanks, best regards
Eric

Please Log in to join the conversation.

3 years 6 months ago #320799 by krileon
Replied by krileon on topic Code field validation

I can only use ONE error message for all code validations?

Yes, due to the bug.

Ok, I can wait on the update, just to understand, how it is at the moment.

Update should be out today or tomorrow for CB Code Field that'll fix this in addition to adding some new features.

One way you can prepare for the update is just use a string as the validation error and translate that string. Example as follows.

Validation Error: Whoops, you can't set this greater than today!

Your language override would then look like the below.

Key: Whoops, you can't set this greater than today!
Text: YOU BROKE IT!

This kind of lets you prepare translations in advance with English fallback built in.


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 6 months ago #320805 by krileon
Replied by krileon on topic Code field validation
CB Code Field 2.1.0 is now available. The validation error message behavior has been fixed so you shouldn't have any issues translating it now. Change log can be found below and should have a blog up by end of day tomorrow with what's new/fixed.

forge.joomlapolis.com/projects/cb-cbcodefield/issues?query_id=165


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.
The following user(s) said Thank You: ericmuc

Please Log in to join the conversation.

3 years 6 months ago - 3 years 6 months ago #321129 by ericmuc
Replied by ericmuc on topic Code field validation

ericmuc wrote: Hi,
Great, this information I needed, now it works. I had only change to

return strtotime( '[value]' ) >= strtotime( '[DATE_FIELD_2]' );
Thanks a lot, best regards
Eric


Hi,
I tried to get this validation only if [Date_Field_2] is not empty. But I cannot get the right code.

Best would be:

I have: [Date_Field_1], [Date_Field_2]

1) I need: [Date_Field_1] may not be equal or greater than now
Code:
if ( strtotime( '[DATE_FIELD_1]' ) > strtotime( 'now' ) ) {
	return false;
}

2) I need: [Date_Field_1] may not be greater than [Date_Field_2], but if [Date_Field_2] is empty, nothing shall be done

I tried to get the code for all three variations ( [Date_Field_1] <= now, [Date_Field_1] < [Date_Field_2] but only if [Date_Field_2] is not empty.

I cannot get this work, do you have a hint for that?

Thanks, best regards
Eric

Please Log in to join the conversation.

3 years 6 months ago #321132 by krileon
Replied by krileon on topic Code field validation
You should be able to exclude empty by checking if it's empty string or equal to empty date or datetime string. Example as follows.

Date Field:
if ( ( '[DATE_FIELD_1]' == '' ) || ( '[DATE_FIELD_1]' == '0000-00-00' ) ) {
	return true;
}

return strtotime( '[DATE_FIELD_1]' ) < strtotime( 'now' );

Datetime Field:
if ( ( '[DATE_FIELD_1]' == '' ) || ( '[DATE_FIELD_1]' == '0000-00-00 00:00:00' ) ) {
	return true;
}

return strtotime( '[DATE_FIELD_1]' ) < strtotime( 'now' );

Beyond that I've already provided example code for you. I'm sorry, but we don't provide custom coding assistance here. I can only provide simple examples. If you need further custom coding help consider hiring a developer to write whatever custom PHP you need.


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.
The following user(s) said Thank You: ericmuc

Please Log in to join the conversation.

3 years 6 months ago #321141 by ericmuc
Replied by ericmuc on topic Code field validation
Hi,

Thanks, that is right and enough. The problem was, I always got the error message because not the return was false but the code. I will try to get the right code now, thanks for your help.

Best regards
Eric

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.222 seconds

Facebook Twitter LinkedIn