Comments (8)
@autowp Deprecated, but not yet removed, and we do not have a replacement lined up. We'll be keeping them for the foreseeable future, and will have alternatives in place and documented when we're ready to remove them for a future v3 revision (if we end up doing one at all).
from zend-inputfilter.
Why are you passing an array of data to setData()
? That should be $filter->setData(false)
, shouldn't it?
from zend-inputfilter.
@weierophinney
This code example is correct, but the unit test in #139 is wrong.
@autowp
No need for the manager. Much simpler: π
$inputFilter = new Zend\InputFilter\InputFilter();
$inputFilter->add(
[
'name' => 'foo',
'required' => false,
]
);
$inputFilter->setData(
[
'foo' => false,
]
);
var_dump($inputFilter->isValid());
var_dump($inputFilter->getMessages());
Output:
boolean false
array (size=1)
'foo' =>
array (size=1)
'isEmpty' => string 'Value is required and can't be empty' (length=36)
from zend-inputfilter.
I figured out the issue with the test. ArrayInputTest
extends from InputTest
, which results in an exception being raised if the value is not within an array. The appropriate solution is to override that test case within ArrayInputTest
in order to pass an array with the false
value.
What's interesting is that if I merge both #138 and #157, and adapt the tests as described above (simple false
value in the InputTest
, overriding the test within ArrayInputTest
to pass an array), the test from #157 passes, but the ArrayInputTest
variant fails with the same message.
This is due to the fact that the fix for #138 does not also patch ArrayInput
line 92, which does the equivalent $empty
definition. However, if I make that change, I now get 158 errors, all against ArrayInputTest
.
From what I can see, this is due to the various allow_empty
and continue_if_empty
flag defaults in that input, and how they interact to determine if a false
value is valid.
I'll see if I can find a solution, but it's looking pretty complex, which leads me back to my initial inclination that we may not want to support this.
from zend-inputfilter.
This can be used:
$inputFilter = new Zend\InputFilter\InputFilter();
$inputFilter->add(
[
'name' => 'foo',
'required' => false,
'allow_empty' => true, // important!
'continue_if_empty' => true, // important!
]
);
$inputFilter->setData(
[
'foo' => false,
]
);
var_dump($inputFilter->isValid()); // true
var_dump($inputFilter->getMessages()); // empty
If an empty string is not allowed, but the value false
(like above):
$inputFilter->get('foo')->getValidatorChain()->prependValidator(
new Zend\Validator\NotEmpty(
[
'type' => [
Zend\Validator\NotEmpty::STRING,
Zend\Validator\NotEmpty::SPACE,
Zend\Validator\NotEmpty::NULL,
Zend\Validator\NotEmpty::EMPTY_ARRAY,
],
]
)
);
$inputFilter->setData(
[
'foo' => '',
]
);
var_dump($inputFilter->isValid()); // false
var_dump($inputFilter->getMessages()); // 'isEmpty' => string 'Value is required and can't be empty'
from zend-inputfilter.
@autowp See the explanation from @froschdesign above; this is already possible, but requires a little configuration on your part: the input must allow_empty
to allow a false
value to validate.
from zend-inputfilter.
@weierophinney
β¦and continue_if_empty
!
from zend-inputfilter.
But both allow_empty
and continue_if_empty
deprecated since 2.4.8
from zend-inputfilter.
Related Issues (20)
- Class Zend\ServiceManager\AbstractPluginManager not found HOT 5
- Avoiding the default NotEmpty::IS_EMPTY validation message. HOT 3
- CollectionInputFilter throws exception on scalar input HOT 3
- ConfigProvider - registration of InputFilterAbstractServiceFactory HOT 1
- [php 7.2] incompatible prototype HOT 2
- InputFilter::getValues() does not throw like it should HOT 2
- Intended behaviour on nested input filters and empty POST data? HOT 2
- FileInput not compatible with PSR (and Dictatoros) UploadedFile HOT 3
- How use Callback validator when field is conditionally required? HOT 3
- Duplicate error messages for collection input field items HOT 14
- Version 2.8.5 broke backward compatibility for apigility HOT 4
- Null value for inputfilter causes exception HOT 28
- Add support for required flag to input filters HOT 2
- collectionRawValues not populated in setData of CollectionInputFilter HOT 15
- MVC InputFilterPluginManager missing InputFilterAbstractFactory config HOT 15
- Input filter specification and merging HOT 1
- Exception when supplying non-array data to an ArrayInput HOT 2
- Empty validation message for file input when sent array for file input HOT 3
- Fatal error: Class 'Zend\ServiceManager\AbstractPluginManager' not found in D:\XAMPP\htdocs\sn\zend-mail\vendor\zendframework\zend-mail\src\Protocol\SmtpPluginManager.php on line 20 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zend-inputfilter.