Fix backend validation for file fields marked as required

Fixes https://github.com/getgrav/grav-plugin-form/issues/78
This commit is contained in:
Flavio Copes
2016-06-28 13:32:39 +02:00
parent ce499c795b
commit 943d2c9892
2 changed files with 15 additions and 2 deletions

View File

@@ -1,3 +1,9 @@
# v1.1.0-rc.4
## 06/xx/2016
1. [](#bugfix)
* Fix backend validation for file fields marked as required [grav-plugin-form#78](Fixes https://github.com/getgrav/grav-plugin-form/issues/78)
# v1.1.0-rc.3
## 06/21/2016

View File

@@ -132,8 +132,15 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
}
$field = $this->items[$field];
if (isset($field['validate']['required'])
&& $field['validate']['required'] === true
&& !isset($data[$name])) {
&& $field['validate']['required'] === true) {
if (isset($data[$name])) {
continue;
}
if ($field['type'] == 'file' && isset($data['data']['name'][$name])) { //handle case of file input fields required
continue;
}
$value = isset($field['label']) ? $field['label'] : $field['name'];
$language = Grav::instance()['language'];
$message = sprintf($language->translate('FORM.MISSING_REQUIRED_FIELD', null, true) . ' %s', $language->translate($value));