MDL-53402 mod_data: Required fields can contain 0.

The number and text field would not accept 0 as a
valid response.
This commit is contained in:
Adrian Greeve
2016-05-02 13:40:05 +08:00
parent 4039f94021
commit c01cbb3e1a
3 changed files with 22 additions and 1 deletions
+10
View File
@@ -94,6 +94,16 @@ class data_field_number extends data_field_base {
return $DB->sql_cast_char2real($fieldname, true);
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
function notemptyfield($value, $name) {
return strval($value) !== '';
}
}
+10
View File
@@ -43,6 +43,16 @@ class data_field_text extends data_field_base {
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
function notemptyfield($value, $name) {
return strval($value) !== '';
}
}
+2 -1
View File
@@ -270,7 +270,8 @@ class data_field_textarea extends data_field_base {
$names = explode('_', $name);
// Clean first.
if (count($names) == 2) {
return !empty($value);
// Don't assume that this is coming from a text editor with tags.
return strval($value) !== '';
}
return false;
}