Skip to Content Skip to Menu

Custom text field validation

  • petekuhn
  • petekuhn
  • ONLINE
  • Posts: 275
  • Thanks: 39
  • Karma: 0
2 days 5 hours ago #343815 by petekuhn
Custom text field validation was created by petekuhn
Is it possible to do custom field validation in PHP? I didn't see it as an option under Validation Rule.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 50379
  • Thanks: 8623
  • Karma: 1472
1 day 13 hours ago #343817 by krileon
Replied by krileon on topic Custom text field validation
Yes, the CB Code Field provides Code Validation where you can supply custom PHP for field validation. As a side note CB Query Field provides Query Validation where you can provide custom SQL for validation.


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.

  • petekuhn
  • petekuhn
  • ONLINE
  • Posts: 275
  • Thanks: 39
  • Karma: 0
1 day 9 hours ago - 1 day 9 hours ago #343827 by petekuhn
Replied by petekuhn on topic Custom text field validation
Thanks. Any advice on debugging the PHP code? 
I use PHPStorm to debug my own components. Can I connect it to this somehow?

Or is there an example of this you can point me to?
Last edit: 1 day 9 hours ago by petekuhn.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 50379
  • Thanks: 8623
  • Karma: 1472
1 day 9 hours ago #343828 by krileon
Replied by krileon on topic Custom text field validation
You can use a custom php file then use an include to include it into the code field. That might allow debug tools to work with it, but I'm not sure since it's string evaluation of code. Otherwise no debug tools likely won't work with it.


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.

  • petekuhn
  • petekuhn
  • ONLINE
  • Posts: 275
  • Thanks: 39
  • Karma: 0
23 hours 43 minutes ago - 22 hours 54 minutes ago #343831 by petekuhn
Replied by petekuhn on topic Custom text field validation
Thanks. As you suspected, I couldn't connect the debugger. But debugged by steps. Evidently, you catch errors and turn them into invalid input. It would be great to see the errors, some sort of debug mode.

My question now is that I can't seem to change the input value in the validation routine. If I change $value and return TRUE, it doesn't change it. Is there a way to do it?

To be clearer, I'm validating a phone number input and I want to transform it into a standard format. I can validate it but not change it.
Last edit: 22 hours 54 minutes ago by petekuhn.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 50379
  • Thanks: 8623
  • Karma: 1472
13 hours 5 minutes ago #343834 by krileon
Replied by krileon on topic Custom text field validation
You can't change the fields value during validation as it's just for validating the supplied value and nothing more. To change a fields value you'd have to process it as part of the storage process either using a custom CB plugin or CB Auto Actions. There's a few triggers this can be done one. They're as follows.

onBeforeprepareFieldDataSave
Code:
$_PLUGINS->trigger( 'onBeforeprepareFieldDataSave', [ &$field, &$user, &$postdata, $reason ] );

That is fired before a field is saved. So it can be used to modify the fields value directly in the $postdata before it ever touches the field. It's a good way to modify the field before server side validation even happens.

onAfterprepareFieldDataSave
Code:
$_PLUGINS->trigger( 'onBeforeprepareFieldDataSave', [ &$field, &$user, &$postdata, $reason ] );

This fires after it has already been bound to the user object so at this point you'd need to modify the value on $user. Either will work and will depend on where in the store process you want to insert custom logic.

If you want client side formatting we do support Input Masks. These let you enforce a format on a field. They're only available for Text fieldtype. You should find the parameters for this under Parameters > Display.


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: petekuhn

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

Moderators: beatnantkrileon
Powered by Kunena Forum