Hi Kenny,
Ok great, glad that's working!
Yes, could can just modify the code a bit to add additional tables. Here's an example:
function conditionalErrorChecking($tableName, $recordExists, $oldRecord) {
$errors = [];
// table 1
if ($tableName === 'your_table_here') {
// conditional error checking rules
$isWarrantyServiced = !empty($_REQUEST['warranty_serviced']);
if ($isWarrantyServiced) {
if (empty($_REQUEST['date_of_service:string'])) { // add :string prefix to date entire date string (if set)
$errors[] = "Please fill out the date of service field.";
}
if (empty($_REQUEST['repair_type'])) {
$errors[] = "Please fill out the repair type field.";
}
$wysiwygWithoutTagsOrWhitespace = trim(strip_tags($_REQUEST['description'] ?? ''));
if (empty($wysiwygWithoutTagsOrWhitespace)) { // wysiwyg, remove all tags and check if empty after that
$errors[] = "Please fill out the description type field.";
}
}
}
// table 2
if ($tableName === 'another_table') {
// error checking code goes here
}
// show errors
if ($errors) {
$errorsHTML = implode("\n", $errors);
die($errorsHTML);
}
}
I previously added some extra variables for readability, they're not strictly necessary.
Let me know if you have any questions about how it works or how to add another table/field.
Dave Edis - Senior Developer
interactivetools.com