I can’t seem to find a straight answer for this: I have a HTML form with nothing special going on, just a couple of text inputs, like so
<input type="text" name="field" />
When posting it, it posts fine, I store the data in a database, no problem. However, when retrieving the form data, I’m seeing nothing stored at all for a field which I filled with ‘0’. I was expecting to see ‘0’ of course, but instead it was nothing, just empty.
I checked in Safari’s dev tools and found out everything I insert into the text field posts just fine, except when I’ve inserted ‘0’, in which case nothing gets posted.
I’ve been searching, I’ve read some W3 docs, but nothing is telling me why inserting ‘0’ into a plain text input posts empty. I’m betting some of you might have a clue or actually know why… and can offer a solution to get the ‘0’ posted without to many tricks.
It seems Safari was incorrect here in reporting ’empty’ when it should be ‘0’. Extra checks confirm that the ‘0’ does get posted. The real reason why the ‘0’ wasn’t stored in the database was because of a check in the backend (PHP):
Because ‘0’ is considered ’empty’, it wasn’t stored. Refactoring the check solved the problem.