Forums

how can I validate the size of a custom array form variable at submission?

floppysheep 17 Feb, 2024
Hi, I've just changed from C6 to C7 and I'm rebuilding my forms. But I'm having trouble finding a functionality I used in C6.

I have several form variables of type array that I need to validate at submission. I need to check if each array contains a specific number of elements. These variables are defined in custom HTML form elements.

in C6, there was a "Validate Data" item that could be placed in the "Submit" action. In the "Fields setup" field of that item I could specify each array, a pre-defined validation rule, plus the error message in a format like:

ARRAYNAME/RULENAME:MESSAGE


Like this example:

CategoryArray/array_contains_three_elements:You must select a total of THREE projects for this category. Please review your selections.


In C7, the Action Editor no longer includes a "Validate data" item. The "Submit" element in the View Editor also doesn't include this. I did find a "Validate Fields" option under form Settings > Behaviors > Data, but it is not configurable. I assume this only toggles validation on/off for validation definitions available in specific field types under "Behaviors", but the HTML element doesn't include a "Validation" option.

So, how in C7 can I validate the size of a form variable array at form submission?
Max_admin 21 Feb, 2024
you may try to use the "Custom function" validation and provide either a javascript or php function
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
floppysheep 21 Feb, 2024
OK, so where exactly do I find this "Custom function" validation? The variables I need to validate are defined in a custom HTML element, and that element has no Behaviors->Validation tab? And there is no Submit action where I can attach a custom function?
You need to login to be able to post a reply.