我使用方法POST在表单中发送var类型DATETIME,日期格式为" 2014-04-20 05:00:47"但是当boleta.php被收回时,这只显示" 2014-04-20"。我不明白,我发布了代码php / html和boleta.php的代码
代码html / php:
<?php $var=array(); ?> <?php foreach ($model as $data): ?> <h1> <?php $var[]= $data->fecha_ingreso; ?></h1> <?php endforeach?> <form action="boleta.php" method="POST" class="form-horizontal" role="form"> <label for="fecha">Select date</label><br> <select name="fecha" class="form-control"> <option value = <?php echo $var[0]; ?> > <?php echo $var[0];?> </option> <option value = <?php echo $var[1]; ?> > <?php echo $var[1];?> </option> <option value = <?php echo $var[2]; ?> > <?php echo $var[2];?> </option> </select> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="pull-right"> <button type="submit" class="btn btn-primary">Send</button> </div> </div> </div> </form>
code boleta.php
<?php date_default_timezone_set("America/Santiago"); echo $_POST['fecha']; ?>
答案 0 :(得分:0)
尝试将您的选项值设置为&#34;来自......
<option value = <?php echo $var[0]; ?> >
到
<option value = "<?php echo $var[0]; ?>" >
也许这就是解决方案
答案 1 :(得分:0)
如果你正确构建了datetime数组。你只需添加&#34;选项值的两侧分配变量,如<option value = "<?php echo $var[0]; ?>" >
。我测试了这个示例html并且适合我。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<form action="boleta.php" method="POST" class="form-horizontal" role="form">
<label for="fecha">Select date</label><br>
<select name="fecha" class="form-control">
<option value='2014-04-20 05:00:47'>'2014-04-20 05:00:47'</option>
<option value='2014-04-21 05:00:47'>2014-04-21 05:00:47</option>
<option value='2014-04-22 05:00:47'>2014-04-22 05:00:47</option>
</select>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="pull-right">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</form>
</body>
</html>
希望它对你有所帮助。