Validations for a Code type field

7 years 8 months ago #285754 by krileon
Replied by krileon on topic Validations for a Code type field
$result= 'the answer';
return $result;

That is always going to validate. The IF condition is a simple if ( $CODE_RETURN_VALUE ). Since you're returning a value other than false, null, or 0 it's going to validate as valid.

$result = false;
return $result;

That is always going to be invalid since you're always returning false UNLESS the field is marked not required and no value has been supplied. I have already tested this on our demo site and it works perfectly fine.

I don't know what more to tell you. It's a simple FALSE if you want to invalidate the input or TRUE if you want to validate it. Your code should do whatever PHP validation you want and it should then do a return of true or false. Do not return anything other than true or false. The parameter specifically tells you this.

Please PM backend super administrator login credentials and will prepare test cases on your site for you to see it working for your self.


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.

7 years 8 months ago #285756 by cpaschen
Replied by cpaschen on topic Validations for a Code type field
I thnk you're missing the 'context' of those entries.

As I noted the "$result = 'the answer';" code is in the parameters | code area - the code that sets the value of the field.

The "$result = false" code is in the integration area.

Doesn't the integration area control the validation all by itself?
Why would setting the value of the field have anything to do with the validation (other than related to the value actually being entered - i.e. 'required')?

Please Log in to join the conversation.

7 years 8 months ago #285760 by krileon
Replied by krileon on topic Validations for a Code type field
Are you trying to add code validation to a code field? I don't understand. A code field has no validation or edit display at all. It just outputs the results of your code. The code validation is for fields with actual user input (e.g. a text field for example).


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.

7 years 8 months ago #285766 by cpaschen
Replied by cpaschen on topic Validations for a Code type field
AHHHHHH.

YES I was trying to use the validation area on a code field type.
Mainly because there was no documentation that said I couldn't.

So I'm guessing that I just need to write the validation code into the element code.

However, I'm guessing that it means that I'm on my own for trying to alert the user when the code creates an invalid value (using joomla notifications).
(Or is there a way I can somehow hook into the SuccessMessage/ErrorMesage display process from within my own code).

OR ... is there an 'onBeforeUserProfileSave' trigger (that only is called during the registration process) that I can use to just run a validation via auto actions?
(is that onBeforeUserProfileSaveREquest? - it's really hard to know exactly when all these triggers happen)

BTW .... I don't think I've ever explained the use-case:

Field 1: Text entry
Field 2: Text entry
Field 3: Text entry
Field 4: CODE (creates a CONCAT of fields 1,2,3)

Validation #1 needed: check the calculated value of Field 4 against a database table of 'bad words' (fail if it finds the Field 4 value in the table)
Validation #2 needed: check the value of Field 4 to make sure nobody else has a an identical value.

Please Log in to join the conversation.

7 years 8 months ago - 7 years 8 months ago #285791 by krileon
Replied by krileon on topic Validations for a Code type field
Your code field shouldn't notify them of a PHP error to begin with as it's of no use to an end user UX wise. It should simply return null if there's nothing valid to output. You can not validate a code field as it's just your custom PHP being output and there's no user input to validate. Fields 1-3 would be where you put any necessary validation

I suppose if you still want to output an error you'd just do it as a return. For example your return could even be an alert as follows.

return '<div class="alert alert-sm alert-danger">Please supply Fields 1-3!</div>';


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.

Moderators: beatnantkrileon
Time to create page: 0.252 seconds

Facebook Twitter LinkedIn