Commit 6e6e52ab authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Allow element to override required rule

parent 8f0620d7
......@@ -30,10 +30,19 @@ defined('INTERNAL') || die();
* Checks whether the field has been specified.
* @param string $field The field to check
* @param array $element The element to check
* @return string The error message, if the value is invalid.
function form_rule_required($field) {
function form_rule_required($field, $element) {
// The array test is for using the "required" rule on file elements
$function = 'form_is_empty_' . $element['type'];
if (function_exists($function)) {
if ($function($field, $element)) {
return get_string('This field is required');
if ($field == '' || is_array($field) && !empty($field['error'])) {
return get_string('This field is required');
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment