下方是日曆選擇器
<input type="date" id="bookdate" value="<?php echo date('Y-m-d'); ?>" min="<?php echo date('Y-m-d'); ?>" max="2017-05-31">
我想要在本頁另一處印出USER所選擇的日期
我使用
<?php echo $_GET[get_data] ?>
來取得值,但試了很多方式就是取得不到
是不是日曆選擇器的值是無法被取得的?
我這邊提供兩個方法,希望有幫助到您~~!
PHP POST
<html>
<head>
    <meta charset="utf-8">
    <title>Q:PHP如何取得HTML 日曆選擇器的值</title>
</head>
<body>
<form action="" method="post">
    select_date :
    <input type="date" value="<?= isset($_POST['get_date']) ? $_POST['get_date'] : ''; ?>" name="get_date"
                         min="<?= date('Y-m-d'); ?>">
    <input type="submit" value="submit_date">
</form>
<?php
if (isset($_POST['get_date'])) {
    echo '<hr>' . 'get_date : ' . $_POST['get_date'];
}
?>
</body>
</html>
JQuery
<html>
<head>
    <meta charset="utf-8">
    <title>Q:PHP如何取得HTML 日曆選擇器的值</title>
</head>
<body>
select_date :
<input type="date" name="get_date">
<hr>
<p id="show_date"></p>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script>
    $(function () {
        $('input[name="get_date"]').blur(function(){
            $('#show_date').text($(this).val());
        });
    });
</script>
感謝大大的幫忙,目前我可以做兩個日期選擇器了
如下
    <form action="" method="get" class="NoPrint">輸入日期:
        <input type="date" name="get_date" value="<?= isset($_GET['get_date']) ? $_GET['get_date'] : ''; ?>">
        <input type="submit" value="送出">
    </form>
		<?php echo $_GET['get_date']; ?>
        
    <form action="" method="get" class="NoPrint">輸入日期:
        <input type="date" name="get_date1" value="<?= isset($_GET['get_date1']) ? $_GET['get_date1'] : ''; ?>">
        <input type="submit" value="送出">
    </form>
		<?php echo $_GET['get_date1']; ?>
想再請教大大一個問題
我需要兩個日期選擇器,並同時取得值印在本頁上
我修改了一下發現他並無法像下拉式選單取得本頁值
請教大大該如何下手修改??
感恩
    <form action="" method="get" class="NoPrint">輸入日期:
        <input type="date" name="get_date" value="?get_data=<?= isset($_GET['get_date']) ? $_GET['get_date'] : ''; ?>&get_data1=<?php echo $_GET[get_data];?>">
        <input type="submit" value="送出">
    </form>
		<?php echo $_GET['get_date']; ?>
        
    <form action="" method="get" class="NoPrint">輸入日期:
        <input type="date" name="get_date1" value="?get_data1=<?= isset($_GET['get_date1']) ? $_GET['get_date1'] : ''; ?>&get_data=<?php echo $_GET[get_data];?>">
        <input type="submit" value="送出">
    </form>
		<?php echo $_GET['get_date1']; ?>
修正一下
  <head>
    <meta charset="utf-8">
    <title></title>
    <!-- NoPrint -->
	<style>  
    .JustPrint {display:none}  
    @media print
    {  
        .JustPrint { display:block; font:9pt verdana; letter-spacing:2px;}  
        .NoPrint {display:none}  
    }  
    </style>  
  </head>
<body>
    <form action="" method="get" class="NoPrint">輸入日期:
        <input type="date" name="get_date" value="?get_data=<?= isset($_GET['get_date']) ? $_GET['get_date'] : ''; ?>&get_data1=<?php echo $_GET[get_data];?>">
        <input type="submit" value="送出">
    </form>
		<?php echo $_GET[get_date]; ?>
        
    <form action="" method="get" class="NoPrint">輸入日期:
        <input type="date" name="get_date1" value="?get_data1=<?= isset($_GET['get_date1']) ? $_GET['get_date1'] : ''; ?>&get_data=<?php echo $_GET[get_data];?>">
        <input type="submit" value="送出">
    </form>
		<?php echo $_GET[get_date1]; ?>
  </body>
</html>
你是要這樣嗎?
<head>
    <meta charset="utf-8">
    <title>PHP如何取得HTML 日曆選擇器的值</title>
</head>
<?php
$date = '';
$date1 = '';
if (isset($_GET['get_date']) && isset($_GET['get_date1'])) {
    $date = $_GET['get_date'];
    $date1 = $_GET['get_date1'];
}
?>
<body>
<form action="" method="get" class="NoPrint">輸入日期:
    <input type="date" name="get_date"
           value="<?= $date ?>">
    <?php
    if (isset($_GET['get_date'])) {
        echo '?get_data=' . $date . '&get_data1=' . $date1;
    }
    ?>
    輸入日期:
    <input type="date" name="get_date1"
           value="<?= $date1 ?>">
    <input type="submit" value="送出">
    <?php
    if (isset($_GET['get_date1'])) {
        echo '?get_data1=' . $date1 . '&get_data=' . $date;
    }
    ?>
</form>
</body>
</html>
感謝大大,可以了。我把我改的貼上,供給需要的人使用吧。
<?php
$date = '';		$date1 = '';		$text = '';
if (isset($_GET['get_date']) && isset($_GET['get_date1']) && isset($_GET['get_date2']) && isset($_GET['get_text'])) {
	$date = $_GET['get_date'];	$date1 = $_GET['get_date1'];	$date2 = $_GET['get_date2'];	$text = $_GET['get_text']; 
	}
?>
<form action="" method="get" class="NoPrint">
	申請日期:
    <input type="date" name="get_date" value="<?= $date ?>" 
    min="<?php echo date ("Y-m-d",strtotime("-1months")); ?>" 
    max="<?php echo date ("Y-m-d",strtotime("+1months")); ?>">
    
    預定生效日:
    <input type="date" name="get_date1"  value="<?= $date1 ?>" 
    min="<?php echo date ("Y-m-d",strtotime("-1months")); ?>" 
    max="<?php echo date ("Y-m-d",strtotime("+1months")); ?>">
    
     實際生效日:
    <input type="date" name="get_date2"  value="<?= $date2 ?>" 
    min="<?php echo date ("Y-m-d",strtotime("-1months")); ?>" 
    max="<?php echo date ("Y-m-d",strtotime("+1months")); ?>">
    <br>
	異 動 事 項 說 明 :
	<textarea name="get_text" cols="40" rows="4" value="<?= $text ?>"></textarea>
    <input type="submit" value="送出資料">
    <br>請先輸入日期
</form>
申請日期:<?php if (isset($_GET['get_date'])){ echo  $date ; } ?><br>
預定生效日:<?php if (isset($_GET['get_date1'])) { echo  $date1 ; } ?><br>
實際生效日:<?php if (isset($_GET['get_date2'])) { echo  $date2 ; } ?><br>
文字:<?php if (isset($_GET['get_text'])) { echo  $text  ; } ?><br>