admin管理员组

文章数量:1325236

I have a form that contains a date picker. The date picker works fine, but when I want to submit its value to the PHP script it, doesn't show. Here is the relevant part of my HTML code:

<body>
    <form action="sub.php" method="post">
        <h2>JsDatePick's Javascript Calendar usage example</h2>

        Look at the ments on the HTML source to fully understand how this very simple example works.

        <input type="text" size="12" id="inputField" name="inputField" />
        <input type="submit" value="submit">
    </form>
</body>

And I want to pick the date value from inputField in this script:

<?php
    echo $date=$_POST['inputField'];
?>

So can you guys tell me how can I get this value from the HTML to the PHP script? I did not show the code of the date picker because that works fine. Thanks in advance.

I have a form that contains a date picker. The date picker works fine, but when I want to submit its value to the PHP script it, doesn't show. Here is the relevant part of my HTML code:

<body>
    <form action="sub.php" method="post">
        <h2>JsDatePick's Javascript Calendar usage example</h2>

        Look at the ments on the HTML source to fully understand how this very simple example works.

        <input type="text" size="12" id="inputField" name="inputField" />
        <input type="submit" value="submit">
    </form>
</body>

And I want to pick the date value from inputField in this script:

<?php
    echo $date=$_POST['inputField'];
?>

So can you guys tell me how can I get this value from the HTML to the PHP script? I did not show the code of the date picker because that works fine. Thanks in advance.

Share Improve this question edited Aug 31, 2012 at 14:23 Ashley Strout 6,2686 gold badges27 silver badges48 bronze badges asked Aug 31, 2012 at 14:15 HarshalHarshal 3,6229 gold badges39 silver badges67 bronze badges 8
  • You're missing your closing </form> tag – Cfreak Commented Aug 31, 2012 at 14:16
  • no i am not showing the full html code – Harshal Commented Aug 31, 2012 at 14:17
  • When you click the input field then click a date on the calendar, does the date actually appear in the textbox? – Ashley Strout Commented Aug 31, 2012 at 14:18
  • 1 var_dump($_POST); And see what's inside. – Leri Commented Aug 31, 2012 at 14:19
  • @D.Strout yes it shows correct value – Harshal Commented Aug 31, 2012 at 14:19
 |  Show 3 more ments

2 Answers 2

Reset to default 4
<?php
    $date = $_POST['inputField'];
    echo $date;
?>

this is the datepicker

<form action="" method="POST">
  <input type="date" name="date">
  <input type="submit" name="submit" value="submit">
</form>

and all the PHP code you need to get up and running is this

<?php
  if(isset($_POST['submit'])) {
      $date = $_POST['date'];
      echo $date;
  }

?> 

this code $date = $_POST['date']; gets the value of the date picker

and this code echo $date; prints out the date you picked

本文标签: javascriptGet value of date picker in PHP codeStack Overflow