如何在PHP中对编号复选框表单中的值进行排序(优先级排序)
我使用下面的代码要求用户对他们更熟悉的编程语言进行排名。 用户需要从1-3排名(1是他们最满意的)如何在PHP中对编号复选框表单中的值进行排序(优先级排序),php,checkbox,echo,ranking,Php,Checkbox,Echo,Ranking,我使用下面的代码要求用户对他们更熟悉的编程语言进行排名。 用户需要从1-3排名(1是他们最满意的) PHP Python Ruby 一旦用户对编程语言进行了优先级排序并点击submit,我如何在下一页回应排名选择?(例如,您的第一个选择是x,第二个选择是y,第三个选择是z)我不确定是否存在标记输入type=“number” 你做得更好 <legend> <label><input type="radio" name="php" value="1">1<
PHP
Python
Ruby
一旦用户对编程语言进行了优先级排序并点击submit,我如何在下一页回应排名选择?(例如,您的第一个选择是x,第二个选择是y,第三个选择是z)我不确定是否存在标记输入type=“number” 你做得更好
<legend>
<label><input type="radio" name="php" value="1">1</label>
<label><input type="radio" name="php" value="2">2</label>
<label><input type="radio" name="php" value="3">3</label>
</legend>
<legend>
<label><input type="radio" name="python" value="1">1</label>
<label><input type="radio" name="python" value="2">2</label>
<label><input type="radio" name="python" value="3">3</label>
</legend>
我会这样做(注意,我已经更改了表单元素上name属性的值):
函数只需按值对数组排序,同时保持键关联。数字类型和所需属性都是有效的HTML。确定,谢谢。我刚才说必需的属性不应该用在radio和checkbox标签中。
<legend>
<label><input type="radio" name="php" value="1">1</label>
<label><input type="radio" name="php" value="2">2</label>
<label><input type="radio" name="php" value="3">3</label>
</legend>
<legend>
<label><input type="radio" name="python" value="1">1</label>
<label><input type="radio" name="python" value="2">2</label>
<label><input type="radio" name="python" value="3">3</label>
</legend>
<form name..... onsubmit = "return check_submit();">
<script>
var check_submit = function(){
if($("input[name=php]:checked").val() =="")
return false;
...
return true;
}
</script>
<input type="text" name="php">
$php = intval(trim($_POST['php']));
$python = intval(trim($_POST['python']));
$msg = "your first choice for php is '.$php;
$msg.="your second choice for phthon is '.$python;
.....etc..
<form id="form1" name="form1" method="post" action="">
<input type="number" name="lang[php]" required="required" max="3" min="1"/>PHP <br />
<input type="number" name="lang[python]" required="required" max="3" min="1"/>Python <br />
<input type="number" name="lang[ruby]" required="required" max="3" min="1"/>Ruby <br /><br />
<input type="submit" name="button" id="button" value="Submit" />
</form>
//Get the form results (which has been converted to an associative array) from the $_POST super global
$langs = $_POST['lang'];
//Sort the values by rank and keep the key associations.
asort($langs, SORT_NUMERIC );
//Loop over the array in rank order to print out the values.
foreach($langs as $lang => $rank)
{
//echo out here first, second, and third rank with each iteration respectively.
}