我想用日期类型显示两个输入的值,但它不起作用。 这是我的代码,
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel ="stylesheet" href="style_wbr.css"/>
<title>PORTAIL</title>
</head>
<body>
<br></br>
<br></br>
<br></br>
<form method = "post" action = "#">
<div id="date">
<input type="date" id="date_deb_filtre" name="Date_de_debut" />
<input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
</form>
<br></br>
<form method="post" action='#'>
<div class="test">
<input type="submit" name="test" id="test" value="test"/>
</div>
</form>
<?php
if(isset($_POST['test']))
{
if (! empty($_POST['date_deb_filtre']) and (!
empty($_POST['date_fin_filtre'])))
{
echo ($_POST['Date_de_debut']);
echo ($_POST['Date_de_fin']);
}
}
?>
</body>
</html>
当我按下测试按钮时,页面上没有显示两个日期,你们可以帮我这个吗
答案 0 :(得分:4)
在测试类之前删除额外的表单标记,并在php中使用 if(!empty($ _ POST ['Date_de_debut'])&amp;&amp;!empty($ _ POST ['Date_de_fin']))
<?php
if(isset($_POST['test']))
{
if (!empty($_POST['Date_de_debut']) && !empty($_POST['Date_de_fin']))
{
echo ($_POST['Date_de_debut']);
echo ($_POST['Date_de_fin']);
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel ="stylesheet" href="style_wbr.css"/>
<title>PORTAIL</title>
</head>
<body>
<br></br>
<br></br>
<br></br>
<form method = "post" action = "#">
<div id="date">
<input type="date" id="date_deb_filtre" name="Date_de_debut" />
<input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
<br></br>
<div class="test">
<input type="submit" name="test" id="test" value="test"/>
</div>
</form>
</body>
</html>
答案 1 :(得分:0)
您正在提交仅存在此标记的第二个表单
<input type="submit" name="test" id="test" value="test"/>
只需删除第二张表格..
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel ="stylesheet" href="style_wbr.css"/>
<title>PORTAIL</title>
</head>
<body>
<br></br>
<br></br>
<br></br>
<form method = "post" action = "#">
<div id="date">
<input type="date" id="date_deb_filtre" name="Date_de_debut" />
<input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
<br></br>
<div class="test">
<input type="submit" name="test" id="test" value="test"/>
</div>
</form>
</body>
</html>
答案 2 :(得分:0)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel ="stylesheet" href="style_wbr.css"/>
<title>PORTAIL</title>
</head>
<body>
<br></br>
<br></br>
<br></br>
<form method = "post" >
<div id="date">
<input type="date" id="date_deb_filtre" name="Date_de_debut" />
<input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
<div class="test">
<input type="submit" name="test" id="test" value="test"/>
</div>
</form>
<?php
if(isset($_POST['test']))
{
if (!empty($_POST['Date_de_debut']) && (!empty($_POST['Date_de_fin'])))
{
echo $_POST['Date_de_debut'];
echo $_POST['Date_de_fin'];
}
}
?>
</body>
</html>
有些愚蠢的错误是你的代码就像你使用两个表单进行单个进程,第二个你可以通过post方法按名称而不是id来获取输入字段的值。尝试使用这个代码这将起作用。
答案 3 :(得分:0)
在if else语句中,您应该使用name
属性而不是id
input
标记。
替换它
empty($_POST['date_deb_filtre'] , empty($_POST['date_fin_filtre']
empty($_POST['Date_de_debut'] , empty($_POST['Date_de_fin']
以下是您的核心代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel ="stylesheet" href="style_wbr.css"/>
<title>PORTAIL</title>
</head>
<body>
<br></br>
<br></br>
<br></br>
<form method = "post" action = "#">
<div id="date">
<input type="date" id="date_deb_filtre" name="Date_de_debut" />
<input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
</form>
<br></br>
<form method="post" action='#'>
<div class="test">
<input type="submit" name="test" id="test" value="test"/>
</div>
</form>
<?php
if(isset($_POST['test'])) {
//echo '<pre>'; print_r($_POST); echo '</pre>'; exit;
if (! empty($_POST['Date_de_debut']) and (! empty($_POST['Date_de_fin']))) {
echo ($_POST['Date_de_debut']);
echo ($_POST['Date_de_fin']);
}
}
?>
</body>
或者你可以试试这个:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel ="stylesheet" href="style_wbr.css"/>
<title>PORTAIL</title>
</head>
<body>
<br></br>
<br></br>
<br></br>
<form method = "post" action = "#">
<div id="date">
<input type="date" id="date_deb_filtre" name="Date_de_debut" />
<input type="date" id="date_fin_filtre" name="Date_de_fin" />
</div>
<div class="test">
<input type="submit" name="test" id="test" value="test"/>
</div>
</form>
<br></br>
<?php
if(isset($_POST['test']))
{
//echo '<pre>'; print_r($_POST); echo '</pre>'; exit;
if (! empty($_POST['Date_de_debut']) and (! empty($_POST['Date_de_fin']))) {
echo ($_POST['Date_de_debut']);
echo ($_POST['Date_de_fin']);
}
}
?>
</body>