There isn't a validation plugin to do that. There's an 'isunique', but that tests to see if the value entered for a single field is unique in the whole table (so does a database lookup to see if any rows already have that field set to that value).
Are your element names actually structured like 'element_1', 'element_2', ..., 'element_85', or do they have different names?
if they are structured like that, you could do a loop ...
Code:
$found = 0;
for ($x = 1; $x <= 85; $x++) {
if ($formModel->formData['yourtable___element_' . $x][0] === 'H') {
$found ++;
}
if ($found >= 2) {
return false;
}
}
return true;
If the names aren't structured in such a way that you can use a loop like that, you'll have to create an array of all the element names you want to check, and loop through that.
Rather than putting the above code in every PHP validation, I'd recommend using the Custom class feature. Here's how to do that, with code using an array of elements names. If your names are sequential, just replace the 'foreach' loop in the following code with the one above, and get rid of the $elements array.
Rename the file ...
libraries/fabrik/fabrik/Helpers/CustomSample.php
... to ...
libraries/fabrik/fabrik/Helpers/Custom.php
... and follow the instructions within it - so rename 'class CustomClass' to 'class Custom'.
Then replace the example 'doMyThing' function with this. You can call the function whatever you want, it doesn't have to be "checkUnique".
Code:
/**
* Validation function called by elements on form "My Form Name"
* (replace this comment with whatever makes sense so you (or someone else) will know what it does in the future)
*/
static public function checkUnique($formModel)
{
// replace the names in this array with all the elements you want to check
$elements = array(
'yourtable___element1',
'yourtable___element2',
'yourtable___element3'
);
$found = 0;
foreach ($elements as $element) {
if ($formModel->formData[$element][0] === 'H') {
$found ++;
}
if ($found >= 2) {
return false;
}
}
return true;
}
Then, in your PHP validations, do ...
Code:
return FabrikCustom::checkUnique($formModel);
The advantage of using the Custom class and just calling your function from within the validation is that if you ever need to change the code (like you add a new element, or value that needs testing), you only have to change the code in one place, not 85.
NOTE - be careful when creating and editing this file. If you break it such that it errors out, your site won't load, as this file gets loaded automatically, on every page load.
-- hugh