1
I tried to do with isset
, guy:
$var1 = isset($_POST["namedocampo"]) ? $_POST["namedocampo"] : date('d/m/Y');
And with if
, guy:
if ($_POST["namedocampo"] == "") {
$var1 = date('d/m/Y');
}
But whenever the field is not filled in the date appears 31/12/1969
.
The date input field looks like this:
<input type="text" id="iddocampo" name="namedocampo" class="form-control" maxlength="10" placeholder="dd/mm/aaaa" onkeyup="formatar('##/##/####', this, event)"></label>
And the exit field is like this:
<li class="list-group-item">
<span class="badge"><?php echo date("d-m-Y",strtotime($var1)); ?></span>
Data:
</li>
Have you tried looking in the Firefox/Chrome console to see what the form is sending to the server? You would expect this
keyup
ensure that the empty field sends the empty string to the server, but this is actually what is happening?– user25930
That one
keyup
is to call a function in js to format the date and validate the field to open a button. The answer below worked... Thanks.– gustavox