diff options
author | Malf Furious <m@lfurio.us> | 2016-03-27 23:59:08 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2016-03-27 23:59:08 -0400 |
commit | 1f8b53e426b8c0a1546e9d5c21573be9003cb556 (patch) | |
tree | 4a77b306ea8bf253d9e62c880e5a666e32ce8158 /app/class | |
parent | 8ad6e8f9223bd3ee214478b3e1247f9c7d8e91ec (diff) | |
download | scrott-1f8b53e426b8c0a1546e9d5c21573be9003cb556.tar.gz scrott-1f8b53e426b8c0a1546e9d5c21573be9003cb556.zip |
Update function Form::populate() to initialize fields added with Form::field_file()
Set $form->[name] for each file field type setup on the form.
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/form.class.php | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/app/class/form.class.php b/app/class/form.class.php index e748afc..529c480 100644 --- a/app/class/form.class.php +++ b/app/class/form.class.php @@ -105,7 +105,7 @@ class Form /* * Populate the form with input data from web page */ - function populate($input) + function populate($input, $files = null) { /* detect duplicate names */ $names = array(); @@ -115,6 +115,8 @@ class Form $names[] = $fld['name']; foreach ($this->enumFields as $fld) $names[] = $fld['name']; + foreach ($this->fileFields as $fld) + $names[] = $fld['name']; if (count(array_unique($names)) != count($names)) { @@ -195,6 +197,38 @@ class Form $this->logError($fld['name'] . " is required"); } + /* init file fields */ + foreach ($this->fileFields as $fld) + { + if (!is_null($files) && isset($files[$fld['name']])) + { + $file = $files[$fld['name']]; + + if ($file['error'] > 0) + { + $this->logError("An unknown error occurred"); + continue; + } + + if ($file['size'] > $fld['maxsize']) + { + $this->logError("File must be no larger than " . $fld['maxsize'] . " bytes"); + continue; + } + + if (is_array($fld['mime']) && array_search($file['type'], $fld['mime']) === false) + { + $this->logError("File type is not supported"); + continue; + } + + $this->$fld['name'] = $file; + } + + else if ($fld['req']) + $this->logError($fld['name'] . " is required"); + } + /* return */ return count($this->errorlist) == 0; } |