我希望通过表单提交id、工作日、月份、月日、时间、时区、年份、本地IP内部和全局IP内部,并以$_POST结束。然而,时区不起作用,我不知道为什么。时区由SELECT元素控制,每个标记的名称为"tz"。
以下是视图中表单的代码:
<form action='/mysecureview/admin_view/log_index.php' method='post'>
<ul>
<input type='hidden' value='<?php echo $id; ?>' name='id'>
<li><label>weekday</label><input <?php echo (($weekday_error == TRUE)?"id='weekday_error'":'')?> type='text' value='<?php echo $wd; ?>' name='wd'></li>
<li><label>month</label><input <?php echo (($month_error == TRUE)?"id='month_error'":'')?> type='text' value='<?php echo $m; ?>' name='m'></li>
<li><label>month-day</label><input <?php echo (($month_day_error == TRUE)?"id='month_day_error'":'')?> type='text' value='<?php echo $md; ?>' name='md'></li>
<li><label>time</label><input <?php echo (($time_error == TRUE)?"id='time_error'":'') ?> type='text' value='<?php echo $t; ?>' name='t'></li>
<select>
<option value="0">Please, select timezone</option>
<?php
foreach(tz_list() as $t) { ?>
<option value="<?php print $t['zone']?>"<?php echo "name='tz'";?> >
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] . ' ';
?>
</option>
<?php } ?>
</select>
<li><label>year</label><input <?php echo (($year_error == TRUE)?"id='year_error'":'') ?> type='text' value='<?php echo $y; ?>' name='y'></li>
<li><label>inside local IP address</label><input <?php echo (($ilp_error == TRUE)?"id='ilp_error'":'') ?> type='text' value='<?php echo $ilp ?>' name='ilp'></li>
<li><label>inside global IP address</label><input <?php echo (($igp_error == TRUE)?"id='igp_error'":'') ?> type='text' value='<?php echo $igp ?>' name='igp'></li>
<li><input type='submit' value='submit' name='show'></li>
<input type='hidden' value='update-log' name='action'>
</ul>
</form>
在控制器中,我使用var_dump($_POST);以获得以下输出:
array(10) {
["id"] "3"
["wd"] "Mon"
["m"] "Mar"
["md"] "4"
["t"] "15:01:43"
["y"] "2015"
["ilp"] "10.18.149.220"
["igp"] "127.221.137.254"
["show"] "submit"
["action"] "update-log"
}
为什么PHP不通过$_POST['tz']发送时区?
您需要将name
赋予您的select
标签
<select name="tz">
<option value="0">Please, select timezone</option>
<?php
foreach(tz_list() as $t) { ?>
<option value="<?php print $t['zone']?>"<?php echo "name='tz'";?> >
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] . ' ';
?>
</option>
<?php } ?>
</select>
因为您的<select>
没有name
属性
给select标签一个名称属性
<select name="tz">
<option value="0">Please, select timezone</option>
<?php
foreach(tz_list() as $t) { ?>
<option value="<?php print $t['zone']?>"<?php echo "name='tz'";?> >
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] . ' ';
?>
</option>
<?php } ?>
</select>
在没有name标记的情况下添加带有select标记的name属性,您无法在任何输入字段的php$_POST变量中获取该属性