Data processing in php form

Asked

Viewed 35 times

0

I would like to know how or if it is possible to put in the form a date field where the user will insert in the format "22 February 2019", or some way to convert to this to save in the database, thanks.

  • You need to convert the month to English or number anyway, so it already converts everything at once to standard format

  • Everything is possible, but not everything is simple or easy. What if the user enters the month "February", everything is tiny? What if you type wrong, like "fefereiro"? It is not easier to create a field <input type="date"> and the user select the day? Much simpler, easy for both involved and mainly already has the desired formatting.

1 answer

1

You can try to create one that contains the fields of the months and the values returned by them are the numbers of each month. For example:

<select name="mes">
  <option value="01">Janeiro</option>
  <option value="02">Fevereiro</option>
  <option value="03">Março</option>
  <option value="04">...</option>
</select>
And in php:

<?php
$dia = $_POST['dia'];
$mes = $_POST['mes'];
$ano = $_POST['ano'];

$valor_formatado_para_mysql = "$ano/$mes/$dia";

?> 

After that, just do the INSERT normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.