从本年度开始的PHP选择菜单
我正在使用Bootstrap和PHP。formmail可以工作,但下面代码中的最后一个选项值(年份)会打印上一个选项值(日期)的值。我不确定哪里出了错 价值观发布到电子邮件: 按月供应。:1 按日供应 按年送达:2(年与日相同)从本年度开始的PHP选择菜单,php,drop-down-menu,Php,Drop Down Menu,我正在使用Bootstrap和PHP。formmail可以工作,但下面代码中的最后一个选项值(年份)会打印上一个选项值(日期)的值。我不确定哪里出了错 价值观发布到电子邮件: 按月供应。:1 按日供应 按年送达:2(年与日相同) 月* 我已经很久没有使用php了,但是这个问题是否与date(“Y”)返回字符串而不是int有关 尝试将$year分配更改为 $year = intval(date("Y")); $yearto = $year+10; 试试这个,它会解决你的问题 <?php
月*
我已经很久没有使用php了,但是这个问题是否与date(“Y”)返回字符串而不是int有关
尝试将$year分配更改为
$year = intval(date("Y"));
$yearto = $year+10;
试试这个,它会解决你的问题
<?php
if(isset($_POST['submit-form'])){
$selectedMonth = $_POST['Serve_by_Month']; //This will give you the month
$selectedDay = $_POST['Serve_by_Day']; //This will give you the day
$selectedYear = $_POST['Serve_by_Year']; //This will give you the year
echo 'date: '.$selectedMonth.'-'.$selectedDay.'-'.$selectedYear;
echo '<br>';
}
?>
<form method="post">
<select id="Serve_by_Month" name="Serve_by_Month" required>
<option value="">Month*</option>
<?php
for($i=1;$i<13;$i++){
$selected = $i==$exp_mo ? 'selected' : '';
?>
<option value="<?=$i?>" <?=$selected?>>
<?=sprintf("%02d",$i)?>
</option>
<?php } ?>
</select>
<br class="hidden-lg">
<select id="Serve_by_Day" name="Serve_by_Day" required>
<option value="">Day*</option>
<?php
for($i = 1; $i <= 31; $i++){ ?>
<option value="<?=$i?>"><?=$i?></option>
<?php }
?>
</select>
<select id="Serve_by_Year" name="Serve_by_Year" required>
<option value="">Year*</option>
<?php
for($i = date('Y'); $i <= date('Y')+10; $i++){?>
<option value="<?=$i?>"><?=$i?></option>
<?php }
?>
</select>
<input type="submit" name="submit-form"/>
</form>
月*
提交后您的php代码是什么?上面的代码有一个未定义的变量exp\u mo
-但似乎在下拉列表中工作,您的代码将在2027年之前打印。如果您关心发布到动作脚本的值,那么我们也需要查看动作脚本。@RamRaider good call。完全错过了。尽管如此,在解决了这个问题之后,我仍然有同样的问题。将实现这里提到的其他一些想法。@ControlZ它对我起了作用。提交后,它是否正确地回显了日期?不幸的是,您提到的代码产生了完全相同的结果。
<?php
if(isset($_POST['submit-form'])){
$selectedMonth = $_POST['Serve_by_Month']; //This will give you the month
$selectedDay = $_POST['Serve_by_Day']; //This will give you the day
$selectedYear = $_POST['Serve_by_Year']; //This will give you the year
echo 'date: '.$selectedMonth.'-'.$selectedDay.'-'.$selectedYear;
echo '<br>';
}
?>
<form method="post">
<select id="Serve_by_Month" name="Serve_by_Month" required>
<option value="">Month*</option>
<?php
for($i=1;$i<13;$i++){
$selected = $i==$exp_mo ? 'selected' : '';
?>
<option value="<?=$i?>" <?=$selected?>>
<?=sprintf("%02d",$i)?>
</option>
<?php } ?>
</select>
<br class="hidden-lg">
<select id="Serve_by_Day" name="Serve_by_Day" required>
<option value="">Day*</option>
<?php
for($i = 1; $i <= 31; $i++){ ?>
<option value="<?=$i?>"><?=$i?></option>
<?php }
?>
</select>
<select id="Serve_by_Year" name="Serve_by_Year" required>
<option value="">Year*</option>
<?php
for($i = date('Y'); $i <= date('Y')+10; $i++){?>
<option value="<?=$i?>"><?=$i?></option>
<?php }
?>
</select>
<input type="submit" name="submit-form"/>
</form>