Set current date in PHP and put in HTML value in an input type = 'date'
I tried as follows but it doesn't work
<form action="add.php" method="POST" name="form1">
<div class="w3-section">
<label>Nome do funcionario</label>
<input class="w3-input w3-border" placeholder="Nome" type="text" name="name" required>
</div>
<div class="w3-section">
<label>Horario</label>
<input class="w3-input w3-border" placeholder="Hora" type="text" name="hora" required>
</div>
<div class="w3-section">
<label>Data</label>
<input class="w3-input w3-border" value="<?php echo date('d/m/Y');?>" type="date" name="data" required>
</div>
<button type="submit" class="w3-button w3-padding-large w3-green w3-margin-bottom">Adicionar <i class="fa fa-plus"></i></button>
</form>
It ignores the value Part
0
Author: Icaro Martins, 2018-04-12
2 answers
Try as follows:
<form action="add.php" method="POST" name="form1">
<div class="w3-section">
<label>Nome do funcionario</label>
<input class="w3-input w3-border" placeholder="Nome" type="text" name="name" required>
</div>
<div class="w3-section">
<label>Horario</label>
<input class="w3-input w3-border" placeholder="Hora" type="text" name="hora" required>
</div>
<div class="w3-section">
<label>Data</label>
<input class="w3-input w3-border" value="<?php echo date('Y-m-d');?>" type="date" name="data" required>
</div>
<button type="submit" class="w3-button w3-padding-large w3-green w3-margin-bottom">Adicionar <i class="fa fa-plus"></i></button>
</form>
Replacing date('d/m/Y')
with date('Y-m-d')
, as this is the proper format for input type='date'
Note: If you modify what I indicated in the snippet will not work because here in the stack there is no snippet php
0
Author: David Alves, 2018-04-12 19:55:53
The format of the attribute value of the field type date
must be in the format yyyy-mm-dd
or the format of php (date('Y-m-d')
), the format displayed will depend on the browser location setting. Remember that not all browsers support this type of field.
<form action="add.php" method="POST" name="form1">
<div class="w3-section">
<label>Nome do funcionario</label>
<input class="w3-input w3-border" placeholder="Nome" type="text" name="name" required>
</div>
<div class="w3-section">
<label>Horario</label>
<input class="w3-input w3-border" placeholder="Hora" type="text" name="hora" required>
</div>
<div class="w3-section">
<label>Data</label>
<input class="w3-input w3-border" value="<?php echo date('Y-m-d');?>" type="date" name="data" required>
</div>
<button type="submit" class="w3-button w3-padding-large w3-green w3-margin-bottom">Adicionar <i class="fa fa-plus"></i></button>
</form>
0
Author: Evandro Lacerda, 2018-04-12 19:51:52