[英]How should I label a select drop down list so the choice is passed to my php script?
I have kind of mastered input boxes. 我有一种熟练的输入框。 I put them as gaps in a text in a form, the student fills in the gaps and sends the form, which calls the php. 我将它们作为空白放在表格的文本中,学生填写空白并发送表格,该表格称为php。
<form action="php/thankyou18BEsW1.php" method="POST" name="myForm" onsubmit="return checkForExpiration();" >
Some text<INPUT TYPE="Text" NAME="G1" size="15"> some more text.
My php script has at the top: 我的php脚本位于顶部:
//should mail the contact form
<?php
$studentnr = $_POST['sn'];
$q1 = $_POST['G1'];
and sure enough, the value in the textbox G1, and all the others, get sent to me OK. 可以肯定的是,文本框G1中的值以及所有其他值都可以发送给我。
Soemtimes, I would like to use a drop-down box. Soemtimes,我想使用一个下拉框。 The students should choose a word. 学生应该选择一个单词。 Here on stackoverflow I found the following. 在stackoverflow上,我发现了以下内容。 I hope that is the right way to do this! 我希望这是正确的方法!
<select >
<option value="" disabled selected>Please select a word...</option>
<option>this</option>
<option>that</option>
</select>
I'm not quite sure where to put NAME="G1". 我不太确定将NAME =“ G1”放在哪里。 In <select>
or in <option>
??? 在<select>
或<option>
When I do this with radio buttons I have banks of radio buttons like this: 当我使用单选按钮执行此操作时,会出现如下所示的单选按钮组:
<input type="radio" name="G30" value="A">A
<input type="radio" name="G30" value="B">B
<input type="radio" name="G30" value="C">C
<input type="radio" name="G30" value="D">D
and that works. 那行得通。 So I'm thinking I should put name="G1" in 所以我想我应该将name =“ G1”放入
<option name="G1">this</option>
<option name="G1">that</option>
<option name="G1">whatever</option>
Will that work like that? 这样行吗? Is there some other, better way? 还有其他更好的方法吗?
<select name="country_code">
<option value="us">United States</option>
<option value="fr">France</option>
</select>
and then in PHP: 然后在PHP中:
$countryCode = $_POST['country_code'];
if ($countryCode === 'fr') { /*...*/ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.