We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c247a41 + 0ff86ea commit 9536357Copy full SHA for 9536357
CHANGELOG.md
@@ -4,9 +4,10 @@ All notable changes to this project will be documented in this file.
4
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
and this project adheres to [Semantic Versioning](http://semver.org/).
6
7
-## [2.0.4] - 2017年12月14日
+## [2.0.4] - 2018-03-XX
8
### Fixed
9
- `data` and `files` were wrongly exposed on `Form` class. Changed visibility to private and added `getData` and `getFiles` methods.
10
+ - Allow non-required file fields
11
12
## [2.0.3] - 2017年12月13日
13
### Added
src/Fields/FileField.php
@@ -31,10 +31,11 @@ public function __construct(array $args = array())
31
32
public function validate($value)
33
{
34
- if (is_null($value) && !$this->required) {
+ if (0 == $value->size && !$this->required) {
35
return;
36
}
37
- if (is_null($value) && $this->required || 0 == $value->size && $this->required) {
+
38
+ if (0 == $value->size && $this->required) {
39
throw new ValidationError($this->error_messages['required'], 'required');
40
41
@@ -54,9 +55,6 @@ public function validate($value)
54
55
56
public function toNative($value)
57
- if (is_null($value)) {
58
- return null;
59
- }
60
if (!is_array($value)) {
61
throw new ValidationError(msg("INVALID_FILE"), 'invalid');
62
src/Validators/FileTypeValidator.php
@@ -24,7 +24,7 @@ public function __construct(array $valid_filetypes, $message = null)
24
25
public function __invoke($value)
26
27
- if (!is_null($this->valid_filetypes) && !in_array($value->type, $this->valid_filetypes)) {
+ if ($value->size > 0 && !is_null($this->valid_filetypes) && !in_array($value->type, $this->valid_filetypes)) {
28
$message = msg($this->message, array(
29
"valid_types" => implode(", ", $this->valid_filetypes),
30
"type" => $value->type
tests/unit/Fields/FileFieldTest.php
@@ -22,12 +22,13 @@ public function testConstruct()
22
23
/**
* @expectedException PHPForm\Exceptions\ValidationError
- * @expectedExceptionMessage The submitted file is empty.
+ * @expectedExceptionMessage This field is required.
*/
public function testValidateEmpty()
$data = array('size' => 0);
- $this->field->validate((object) $data);
+ $field = new FileField(["max_size" => 20, "required" => true]);
+ $field->validate((object) $data);
tests/unit/Validators/FileTypeValidatorTest.php
@@ -11,7 +11,7 @@ class FileTypeValidatorTest extends TestCase
public function setUp()
14
- $this->data = (object) array('type' => 'image/png');
+ $this->data = (object) array('size' => 10, 'type' => 'image/png');
15
16
17
public function testValidType()
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments