Skip to content

Instantly share code, notes, and snippets.

@bmbrands
Last active August 29, 2015 14:15
Show Gist options
  • Save bmbrands/ac5c81a71a9cc808b346 to your computer and use it in GitHub Desktop.
Save bmbrands/ac5c81a71a9cc808b346 to your computer and use it in GitHub Desktop.
Alternative validation
function validation($data, $files) {
$errors = parent::validation($data, $files);
// Check if any item quantities were selected.
// Retrieve order items and amounts.
// First assume the user has not selected anything.
$allempty = true;
// Loop through all of the form fields.
foreach ($data as $field => $value) {
// filter the select boxes
if ($strpos($field, '_type')) {
if ($value != 0) {
// At least one checkbox was selected.
$allempty = false;
}
// Add an error to each field.
$allerrors[$field] = get_string('zeroamount', 'block_realexpayments');
}
}
// Turns out we all is really empty, return the errors
if ($allempty) {
return $allerrors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment