Set current date in PHP and put in value HTML in an input type = 'date'

0

I tried the following but it does not 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

    
asked by anonymous 12.04.2018 / 21:36

2 answers

0

Try this:

<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 appropriate format for input type='date'

    
12.04.2018 / 21:44
0

The format of the attribute value of type date field must be in the format yyyy-mm-dd or the format of php ( date('Y-m-d') ), the format displayed will depend on the location configuration of the browser. 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>  
    
12.04.2018 / 21:46