【发布时间】:2010-11-30 22:21:31
【问题描述】:
好的,我正在使用 $_POST 向自身发送数据。
我有一些默认选中的复选框。 (本例中为 1 和 2)
当表单被提交时,我想用 $_POST 值覆盖这些默认值。
<?php
$syndication_check_1 = 'checked="checked"';
$syndication_check_2 = 'checked="checked"';
$syndication_check_3 = '';
if (isset($_POST['syndication'])) {
//
}
?>
<form name="form" method="post" action="">
<!-- this is what I use for radiobuttons -->
<legend>Sex:</legend>
<input type="radio" name="sex" id="sex-1" value="M" <?php echo (!isset($_POST['sex']) || $_POST['sex'] == "M") ? 'checked="checked"': ''; ?> />
<label for="sex-1"><?= _("Male"); ?></label>
<input type="radio" name="sex" id="sex-2" value="F" <?php echo (isset($_POST['sex']) && $_POST['sex'] == "F") ? 'checked="checked"': ''; ?> />
<label for="sex-2"><?= _("Female"); ?></label>
<!-- now something similar for checkboxes -->
<legend>Syndication:</legend>
<input type="checkbox" name="syndication[]" id="syndication-1" value="yahoo" <?= $syndication_check_1; ?> /> <!-- checked -->
<label for="syndication-1">Yahoo Real Estate</label>
<input type="checkbox" name="syndication[]" id="syndication-2" value="trulia" <?= $syndication_check_2; ?> /> <!-- checked -->
<label for="syndication-2">Trulia.com</label>
<input type="checkbox" name="syndication[]" id="syndication-3" value="zillow" <?= $syndication_check_3; ?> />
<label for="syndication-3">Zillow.com</label>
</form>
【问题讨论】:
-
如何使用 $_POST 数据值覆盖我的默认值?