简体   繁体   English

我应该如何标记选择下拉列表,以便将选择传递给我的php脚本?

[英]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.

相关问题 php选择下拉选择到会话变量 - php select drop down choice to session variable 我如何链接两个下拉菜单框,我可以选择一个菜单,它应该在其他下拉框中显示我的列表? - how can i link two drop down menu box where i can select one menu and it should show my list in other drop down box? 如何使用PHP在首页加载下拉列表中设置默认选项? - How to set default choice in drop down list on first page load using PHP? 用php创建选择下拉列表的计数器? - Create Counter of select drop down list with php? 如何从我的php下拉列表中选择内容并将其转换为变量? - how do I take selection from my php drop down list and turn it into a variable? 如果下拉列表在php代码中,如何在下拉列表中选择年份? - How can I get year selected in drop down list if drop down list is in php code? 如何在Laravel PHP中验证下拉列表? - How do I validate a drop down list in Laravel PHP? 如何使我的动态下拉列表也依赖于父下拉列表? - How can I make my dynamic drop-down list be dependent dependent also to parent drop down? 我将如何使用下拉列表使用选择查询来更新基于所选选项的文本字段(php/mysql) - How would I go about using a drop down list using a select query to update text fields based on selected option (php/mysql) 下拉列表-用URL编写的选择 - Drop Down List - Choice written in URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM