POST后的PHP表单值
我有一个表单,在上面用PHP发布数据。 发送数据时,我希望显示新值。 在文本字段上执行此操作很容易,但是如何在RadioBox上设置新值呢。 这里我的默认值是男性 PHP HTMLPOST后的PHP表单值,php,forms,post,Php,Forms,Post,我有一个表单,在上面用PHP发布数据。 发送数据时,我希望显示新值。 在文本字段上执行此操作很容易,但是如何在RadioBox上设置新值呢。 这里我的默认值是男性 PHP HTML 尝试使用print\r($\u POST);出口查看变量POST中发送的值 name=“sex”value=“F”/>女性 <input type="radio" <?php if ($_POST['sex'] == "M") print "checked=\"checked\"";?> name=
尝试使用print\r($\u POST);出口查看变量POST中发送的值 name=“sex”value=“F”/>女性
<input type="radio" <?php if ($_POST['sex'] == "M") print "checked=\"checked\"";?> name="sex" value="M" /> Male
<input type="radio" <?php if ($_POST['sex'] == "F") print "checked=\"checked\"";?> name="sex" value="F" /> Female
请尝试以下方法:
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="name">Name:</label>
<input type="text" name="name" size="30" value="<?php echo (isset($_POST['name'])) ? $_POST['name'] : ""; ?>">
<br /><br />
<label for="email">Sex:</label>
<input type="radio" name="sex"<?php echo (@$_POST['sex'] == "M") ? 'checked="checked"' : "";?> value="M" /> Male
<input type="radio" name="sex" <?php echo (@$_POST['sex'] == "F") ? 'checked="checked"' : "";?> value="F" /> Female
</form>
你知道Sex radiobox…M和F的值。你想知道需要检查哪一个。这将默认选中的是男性,就像您当前拥有的一样
<input type="radio" <?php echo (!isset($_POST['sex']) || $_POST['sex'] == "M") ? 'checked="checked"': ''; ?> name="sex" value="M" /> Male
<input type="radio" <?php echo (isset($_POST['sex']) && $_POST['sex'] == "F") ? 'checked="checked"': ''; ?> name="sex" value="F" /> Female
name=“sex”value=“F”/>女性
如果选择了值,则必须添加checked=“checked”。查看答案了解详细信息。实际上,Aarons示例正是我想要的,默认值为“M”选中。语句()的拼写错误:,不
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="name">Name:</label>
<input type="text" name="name" size="30" value="<?php echo (isset($_POST['name'])) ? $_POST['name'] : ""; ?>">
<br /><br />
<label for="email">Sex:</label>
<input type="radio" name="sex"<?php echo (@$_POST['sex'] == "M") ? 'checked="checked"' : "";?> value="M" /> Male
<input type="radio" name="sex" <?php echo (@$_POST['sex'] == "F") ? 'checked="checked"' : "";?> value="F" /> Female
</form>
<input type="radio" <?php echo (!isset($_POST['sex']) || $_POST['sex'] == "M") ? 'checked="checked"': ''; ?> name="sex" value="M" /> Male
<input type="radio" <?php echo (isset($_POST['sex']) && $_POST['sex'] == "F") ? 'checked="checked"': ''; ?> name="sex" value="F" /> Female