Permalink
Browse files

BUGFIX Better checking of file validity (#6093) Thanks Pigeon (from r…

…113419)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114533 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 100e50c commit c24ed58d2de17a7547dd640a8d219d5806dae3f3 @sminnee sminnee committed Dec 5, 2010
Showing with 9 additions and 4 deletions.
  1. +9 −4 forms/RequiredFields.php
View
@@ -10,7 +10,7 @@
* @subpackage validators
*/
class RequiredFields extends Validator {
-
+
protected $required;
protected $useLabels = true;
@@ -98,14 +98,19 @@ function php($data) {
$valid = ($field->validate($this) && $valid);
}
if($this->required) {
- foreach($this->required as $fieldName) {
+ foreach($this->required as $fieldName) {
$formField = $fields->dataFieldByName($fieldName);
$error = true;
// submitted data for file upload fields come back as an array
$value = isset($data[$fieldName]) ? $data[$fieldName] : null;
if(is_array($value)) {
- $error = ($value) ? false : true;
+ if ($formField instanceof FileField && isset($value['error']) && $value['error']) {
+ $error = true;
+ }
+ else {
+ $error = (count($value)) ? false : true;
+ }
} else {
// assume a string or integer
$error = (strlen($value)) ? false : true;
@@ -168,4 +173,4 @@ function getRequired(){
}
}
-?>
+?>

0 comments on commit c24ed58

Please sign in to comment.