2

I used Datepicker a few times and always transmitted data with GET. Now I'm trying to use it with POST. Here is my HTML CODE:

<div class="input-group date" name="eintritt" id="datetimepicker_benutzer_detail_start">
  <input type="text" class="form-control" />
  <span class="input-group-addon">
  <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>

And here is my JavaScript:

 $(function () {
$('#datetimepicker_benutzer_detail_start').datetimepicker({
        defaultDate: '2018/01/01',
        format: 'DD.MM.YYYY',
        locale: 'de'
});

Now my question: There is a formular with some text fields and those are sent via POST and stored in a MYSQL table. But how is it possible to get the shown date from the Datepicker? It's not possible with $_POST['eintritt']...

My form tag looks like this:

<form id="benutzer_daten" name="benutzer_daten" method="post" action="<?php echo $_SERVER['REQUEST_URI'];?>">

And the I just get the POST values like this:

$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];

And after there is a normal mysql insert...

dida110
  • 111
  • 1
  • 9

1 Answers1

0

All you have to do is assign a name tag to the input. This is how input gets linked with the php $_POST. So, in your case:

<input type="text" name="vorname" class="form-control" />

will be assigned to

$vorname = $_POST['vorname'];

Also, read this if you are not preventing MySQL injections.

Binar Web
  • 867
  • 1
  • 11
  • 26
  • Thanks, yes but my problem is the input field from datepicker, all other fields are submitted without any problem. This field is not submitting the information. I think there should be a code to write the date while choosing into the value="" field. – dida110 Apr 18 '18 at 11:15
  • I don't understand you completely, but change `vorname` with something else that matches a datetimepicker field name, like `name="datetime"` and use it in PHP like `$_POST['datetime']` – Binar Web Apr 18 '18 at 11:52
  • 1
    Ouu now I saw my mistake, the name field was in the wrong tag (not in the input tag). Thank you! – dida110 Apr 18 '18 at 15:08
  • Glad I could help you! – Binar Web Apr 19 '18 at 06:33