当您从 html 表单中选择单选按钮时,我可以指定您希望运行的 php 代码块吗?
例如,我有许多用户可以填写的字段,但我希望 PHP 代码根据他们选择的单选按钮输出不同的内容。
<html>
<body>
<form action="citation.php" method="post">
<table width="100%" border="0">
<tr>
<td>Name</td>
<td><label for="name2"></label>
<input type="text" name="name" id="name2"></td>
</tr>
<tr>
<td>Number</td>
<td><label for="number"></label>
<input type="text" name="number" id="number"></td>
</tr>
<tr>
<td>Email</td>
<td><label for="email"></label>
<input type="text" name="email" id="email"></td>
</tr>
<tr>
<td>Address</td>
<td><label for="address"></label>
<input type="text" name="address" id="address"></td>
</tr>
<tr>
<td>web</td>
<td><label for="web"></label>
<input type="text" name="web" id="web"></td>
</tr>
<tr>
<td><p>
<label>
<input type="radio" name="RadioGroup1" value="ex1" id="RadioGroup1_0">
ex1</label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="ex2" id="RadioGroup1_1">
ex2</label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="ex3" id="RadioGroup1_2">
ex3</label>
<br>
</p></td>
<td><input type="submit" name="click me" id="click me" value="Submit"></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
因此,如果他们选择第一个单选按钮并单击“提交”,则会输出与选择第二个单选按钮不同的内容。
For example, I have a number of fields a user could fill out but I want the PHP code to spit out something different depending on which radio button they select.
<html>
<body>
<form action="citation.php" method="post">
<table width="100%" border="0">
<tr>
<td>Name</td>
<td><label for="name2"></label>
<input type="text" name="name" id="name2"></td>
</tr>
<tr>
<td>Number</td>
<td><label for="number"></label>
<input type="text" name="number" id="number"></td>
</tr>
<tr>
<td>Email</td>
<td><label for="email"></label>
<input type="text" name="email" id="email"></td>
</tr>
<tr>
<td>Address</td>
<td><label for="address"></label>
<input type="text" name="address" id="address"></td>
</tr>
<tr>
<td>web</td>
<td><label for="web"></label>
<input type="text" name="web" id="web"></td>
</tr>
<tr>
<td><p>
<label>
<input type="radio" name="RadioGroup1" value="ex1" id="RadioGroup1_0">
ex1</label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="ex2" id="RadioGroup1_1">
ex2</label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="ex3" id="RadioGroup1_2">
ex3</label>
<br>
</p></td>
<td><input type="submit" name="click me" id="click me" value="Submit"></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
So, if they choose the first radio button and hit submit, that would spit out something different than if you chose the 2nd radio button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是非常基本的 PHP
甚至更好:
您还可以包含文件,而不是将 HTML 粘贴到 PHP 中:
it's quite basic PHP
or even nicer:
instead of pasteing HTML in th the PHP, you could also include files:
当您进行标准表单提交时,表单字段的
name
字段会自动作为 POST 参数传递给 php,即在$_POST
中。如果字段具有name="test"
和value="valueTest"
,那么在 php 层,您将获得该值$_POST['test ']
。以下是如何处理您的特定情况的示例:When you do standard form submission, the
name
field of form fields automatically are passed to php as POST params, i.e., in$_POST
. If a field hasname="test"
andvalue="valueTest"
, then at the php layer, you will get that value as$_POST['test']
. Below is an example of how to handle your particular case: