Php 显示/隐藏行列式为日期的单选按钮
在报名表中,我可以选择竞赛费用:Php 显示/隐藏行列式为日期的单选按钮,php,radio-button,Php,Radio Button,在报名表中,我可以选择竞赛费用: <p><input type="radio" name="fee" class="date1" value="30"> 30€ until 30 may</p> <p><input type="radio" name="fee" class="date1" value="15">child 15€ until 30 may</p> <p><input typ
<p><input type="radio" name="fee" class="date1" value="30"> 30€ until 30 may</p>
<p><input type="radio" name="fee" class="date1" value="15">child 15€ until 30 may</p>
<p><input type="radio" name="fee" class="date2" value="50"> 50€ until 30 june</p>
<p><input type="radio" name="fee" class="date2" value="25">child 25€ until 30 june</p>
<p><input type="radio" name="fee" class="date3" value="80">80€ until 10 july</p>
<p><input type="radio" name="fee" class="date3" value="40"> 40€ child until 10 july
30欧元至5月30日
5月30日前的15欧元
50欧元至6月30日
儿童25欧元至6月30日
80欧元至7月10日
40欧元至7月10日
如何在5月30日之前只显示表格的前两行(class=date1
)
此后,从5月30日到6月30日只有3-4行(class=date2
)
最后两行从6月30日到7月10日(
class=date3
)根据我对您的问题的理解,以下内容应该有效
<?php $current_time = time(); ?>
<?php if ($current_time < mktime(0, 0, 0, 6, 1, 2015)) { ?>
<p><input type="radio" name="fee" class="date1" value="30"> 30€ until 30 may</p>
<p><input type="radio" name="fee" class="date1" value="15">child 15€ until 30 may</p>
<?php } else if ($current_time < mktime(0, 0, 0, 7, 1, 2015)) { ?>
<p><input type="radio" name="fee" class="date2" value="50"> 50€ until 30 june</p>
<p><input type="radio" name="fee" class="date2" value="25">child 25€ until 30 june</p>
<?php } else if ($current_time < mktime(0, 0, 0, 7, 11, 2015)) { ?>
<p><input type="radio" name="fee" class="date3" value="80">80€ until 10 july</p>
<p><input type="radio" name="fee" class="date3" value="40"> 40€ child until 10 july
<?php } ?>
30欧元至5月30日
5月30日前的15欧元
50欧元至6月30日
儿童25欧元至6月30日
80欧元至7月10日
40欧元至7月10日
请注意,这似乎相当危险,因为我可以轻松地处理请求并发送fee=0。希望您在服务器端有一些错误检查
---编辑---
当接受来自未知来源的输入(例如,网络上的用户)时,请确保不允许所有无效输入。由于此表单上的有效输入数量非常有限,因此可以轻松检查以确保它是有效输入之一
如果没有这样的检查,有人可以更改他们的请求并发送fee=1。他们可能会得到一张1欧元的票。尽管您可能有其他流程来防止这种情况
$current_time = time();
if ($current_time < mktime(0, 0, 0, 6, 1, 2015)) {
if ($_POST['fee'] !== '15' && $_POST['fee'] !== '30') {
// return error
}
} else if ($current_time < mktime(0, 0, 0, 7, 1, 2015)) {
if ($_POST['fee'] !== '25' && $_POST['fee'] !== '50') {
// return error
}
} else if ($current_time < mktime(0, 0, 0, 7, 11, 2015)) {
if ($_POST['fee'] !== '40' && $_POST['fee'] !== '80') {
// return error
}
}
$current_time=time();
if($current_time
我没有完全理解你的问题。谢谢@Tyler Marien这是我要找的,为我工作。是的,我已经检查过类似“如果(空($_POST['fee']){//Adds name to array$data_missing[]='fee';”的内容,或者你想的是什么?我在我的答案中添加了一些错误检查代码。显然,我对整个购票过程一无所知,所以这可能已经用非编程方式处理了(即,在发送门票之前,必须有人审查提交的内容等)。再次感谢@Tyler Marien您为我提供了很多帮助。