我正在尝试创建一个简单的复选框菜单,该菜单将在显示时显示所有选定的值。
test1.php
<form action="test2.php" method="POST">
<input type="checkbox" name="#Example1," />1<br>
<input type="checkbox" name="#Example2," />2<br>
<input type="checkbox" name="#Example3," />3<br>
<input type="checkbox" name="#Example4," />4<br>
<input type="checkbox" name="#Example5," />5<br>
<input type="submit" name="formSubmit" value="Submit" />
</form>
test2.php
<?php
print_r($_POST)
?>
提交后,收到的是......
Array ( [#Example1] => on [#Example2] => on [formSubmit] => Submit )
我希望它显示为......
#Example1, #Example2,
每个结果之间需要有一个逗号,这就是为什么它们最后都有一个逗号。
答案 0 :(得分:0)
<form action="test2.php" method="POST">
<input type="checkbox" name="formDoor[]" value="#Example1" />1<br>
<input type="checkbox" name="formDoor[]" value="#Example2" />2<br>
<input type="checkbox" name="formDoor[]" value="#Example3" />3<br>
<input type="checkbox" name="formDoor[]" value="#Example4" />4<br>
<input type="checkbox" name="formDoor[]" value="#Example5" />5<br>
<input type="submit" name="formSubmit" value="Submit" />
</form>
从您的值中删除逗号并在PHP中执行此操作。
$val = implode(",",$_POST["formDoor"]);
echo $val;