Skip to Content Skip to Menu

Validation field question

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
1 year 10 months ago #331915 by AchLive
Validation field question was created by AchLive
Hi all, I would like to create a text field, or even a different one, that can be validated with respect to an expected value.
Example:
Correct field value as expected value = Promo
I created a text field and used validation with CB Code Field
In validation I wrote the following code but it doesn't work
Code:
$value = 'Promo'; if (str_contains($value))

Can you help me get the result I'm looking for?
Thanks for the support

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

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 10 months ago #331918 by krileon
Replied by krileon on topic Validation field question
Should be able to just use normal REGEXP validation for that since the word is static. Example as follows.

Parameters > Validation
Validation Rule: Custom REGEXP Validation
Custom REGEXP Validation: /promo/

As for why your code doesn't work it's because that's not valid PHP. Sorry, I cannot help you with custom coding without a business membership .


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.

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
1 year 10 months ago #331921 by AchLive
Replied by AchLive on topic Validation field question
Thank you very much!

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

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
1 year 10 months ago #331939 by AchLive
Replied by AchLive on topic Validation field question
I noticed that it only works well if the field is required.
If the field is not set as mandatory then it considers it valid even if left empty and therefore the validation has no effect.
 
These are the settings
 
Thanks for the support

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

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 10 months ago #331942 by krileon
Replied by krileon on topic Validation field question
A field not marked required is optional so of course it skips the validation if left empty. If you want them to always supply a value be sure to mark it required.


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