Skip to Content Skip to Menu

[SOLVED] how can i use custom php function for validation?

  • saman2
  • saman2
  • OFFLINE
  • Posts: 404
  • Thanks: 7
  • Karma: -1
7 years 3 months ago - 7 years 3 months ago #295463 by saman2
hi
i have custom validation for field of user registration and it can't use with Regex because it's little complex.
how can i use my php code?
i find auto action solution and i select OnbeforeRgistration trigger and what type must select for validation? Code type must select? or Field ?
my phpValidation code:
Code:
function isValidCustomCode($input) { # check if input has 10 digits that all of them are not equal if (!preg_match("/^\d{10}$/", $input)) { return false; } $check = (int) $input[9]; $sum = array_sum(array_map(function ($x) use ($input) { return ((int) $input[$x]) * (10 - $x); }, range(0, 8))) % 11; return ($sum < 2 && $check == $sum) || ($sum >= 2 && $check + $sum == 11); }
tnx
Last edit: 7 years 3 months ago by krileon. Reason: Added [SOLVED] tag to subject

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48424
  • Thanks: 8274
  • Karma: 1443
7 years 3 months ago #295468 by krileon
You'd use whatever field you want and under Integrations > CB Code Field tab of that field you can specify the Code Validation if you have CB Code Field. Otherwise you can't use your custom code 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.
The following user(s) said Thank You: saman2

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

  • saman2
  • saman2
  • OFFLINE
  • Posts: 404
  • Thanks: 7
  • Karma: -1
7 years 3 months ago - 7 years 3 months ago #295482 by saman2
how to use that? is there any documantion for validation solution via integrations>CB Code Field?
i'm testing many simple php code but it's not work for me.
can you some simple PHP code example show me?
i'm find www.joomlapolis.com/documentation/350-cb-code-field/tutorials/18534-calculating-years-months-days-from-birthday-field-using-cb-code-fieldthis but not handle me for custom validate my field
Last edit: 7 years 3 months ago by saman2.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48424
  • Thanks: 8274
  • Karma: 1443
7 years 3 months ago - 7 years 3 months ago #295506 by krileon
You edit your field within CB > Field Management then under the Integrations > CB Code Field tab you specify your custom PHP validation. It expects your code to return true for valid and false for invalid. Review parameter descriptions carefully. You will need the CB Code Field plugin to do this.


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.
Last edit: 7 years 3 months ago by krileon.

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

  • saman2
  • saman2
  • OFFLINE
  • Posts: 404
  • Thanks: 7
  • Karma: -1
7 years 3 months ago - 7 years 3 months ago #295513 by saman2
yes i have mistake on the [value] parameter and must use ' ' for that.
it's work very well...
tnx
Last edit: 7 years 3 months ago by saman2.

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

Moderators: beatnantkrileon
Powered by Kunena Forum