Comments (6)
Actually, this is more NFR as this is obviously due to the fact that all POST/GET values are strings, with the exception of array of course.
What I propose we do is have Form::bind
turn empty strings into null
by default before assigning it to the model. For those who, for whatever reason, want empty strings in their databases, they can allow it with something like
$form->allowEmptyStrings(
[
'fieldName'
]
);
or
$field = new Text(
'field',
[
'allowEmptyString' => true
]
);
from phalcon.
@scrnjakovic Looking at this I have one concern. How would Phalcon know that an empty string is indeed an empty string vs. a null? There will be instances where the POST will be an empty string and this would be what I might want to add in the database vs a null.
Thoughs?
from phalcon.
@niden Without getting into a discussion on why would one want empty strings in a database, I suppose there is a valid use case somewhere, I still think those cases are quite rare or at least less common than having nullable
column for when there is no value. So my idea was to treat all empty strings as nulls unless field is explicitly flagged to accept empty strings.
from phalcon.
I am not a fan of storing empty strings either, but reasonable use cases max exist.
It's not an example I'd use personally, but in view
you could decide to print the stored content if it's a string
(even if it's empty), or use an alternative method to gather the content when it's null
.
Filters can be used on Form
elements, so I'd maybe write a Filter
which returns null
if the input is empty then set it to the elements I need.
If it's required on all the elements I'd override Form::add()
in the Form
object.
from phalcon.
@zsilbi I like this approach better because it extends the forms even more for developers.
We already have Validators
for forms (valid/not valid). We can also attach Filters or Transformers or Decorators so that we can achieve this transformation
I will move this to the 4.1 release because this requires significant work.
from phalcon.
Yeah, I don't mind that approach, I just advocate NULL being default and empty string optional. That makes more sense to me.
from phalcon.
Related Issues (20)
- [NFR]: Replace regexp in the router with arrays for extra performance
- Can't access page, 404 FORBIDDEN
- Can I use `$this->getRelated` on already cached data?
- [BUG]: Scrutinizer Fixes HOT 1
- [NFR]: ADD sticky for read write connection
- [NFR]: removeBehavior method in Model
- [NFR]:returnedValue not updated after dispatcher->forward
- [NFR]: No way to add html attributes to Select Tag. documentation inadequate HOT 1
- [BUG]: The "setDefault" method does not work for forms of type "text" with name "value" HOT 5
- update src folder links
- How to use cookie in phalcon 4.x ? HOT 1
- update tests folder links
- [NFR]: Complete rework of ORM HOT 3
- [BUG]: \Phalcon\Encryption\Crypt + named parameters/arguments throw fatal error. HOT 1
- [NFR]: Refactor Phalcon\Mvc\Router/Route HOT 1
- [NFR]: Refactor Phalcon\Mvc\Model\MetaData
- phalcon 3,4 webhook problem HOT 2
- [NFR]: What is the purpose of this library? HOT 3
- [NFR]: Add a getResult() or fetchAll() method to Resultset\Simple
- [BUG]: when i use JWT Builder , api returns blank 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 phalcon.