[英]pulling multiple values from up to seven checkboxes in php
Good evening, I'm working on a project that has a list of seven options a user may select. 晚上好,我正在做一个项目,其中列出了用户可以选择的七个选项。 I'm trying to get all of them to pull with a comma in between.
我试图让所有的人之间都用逗号隔开。 This is not pulling from a db, but from a php form.
这不是从数据库中拉出,而是从PHP表单中拉出。
<html>
<tr><td><font color=black>Select all Constituency Groups that apply:</font></td></tr>
<tr><td><b><hr size=0 color=silver noshade></b></td></tr>
<tr><td><input value="1st Year Student" type="checkbox" name="chkCon[]" id="ChkCon1" /> 1st Year Student</font></td></tr>
<tr><td><input value="2nd Year Student" type="checkbox" name="chkCon[]" id="ChkCon2" /> 2nd Year Student</font></td></tr>
<tr><td><input value="4 Year College Professor" type="checkbox" name="chkCon[]" id="ChkCon3"/> 4 Year College Professor</font></td></tr>
<tr><td><input value="Adjunct Faculty" type="checkbox" name="chkCon[]" id="ChkCon4" /> Adjunct Faculty</font></td></tr>
<tr><td><input value="Alumni/Graduate" type="checkbox" name="chkCon[]" id="ChkCon5"/> Alumni/Graduate</font></td></tr>
<tr><td><input value="High School Teacher" type="checkbox" name="chkCon[]" id="ChkCon6" /> High School Teacher</font></td></tr>
<tr><td><input value="Industry Representative" type="checkbox" name="chkCon[]" id="ChkCon7" /> Industry Representative</font></td></tr>
</table>
</html>
I'm not sure if i need to name them the same or not. 我不确定是否需要使用相同的名称。 But here is the post
但是这里是帖子
if (!empty($_REQUEST['chkCon[]'])) {
$ChkCon = $_REQUEST['chkCon[]'];
} else {
$ChkCon = "";
}
Thank you 谢谢
$chkCon = $_REQUEST['chkCon'];
$values = "";
for ($i=0;$i<count($chkCon);$i++) {
$values .= $chkCon[$i];
if ($i<count($chkCon)-1) {
$values .= ",";
}
}
echo $values;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.