处理 php 中的复选框数组
好的,我正在制作一个电子邮件表单,需要在复选框数组中获取一堆要打印的项目...或转换为字符串...这样它们就可以变成变量...
这就是表单的内容看起来像:
它后面有 html:
<th valign="top" scope="row">Receive further information_on: </th>
<td width="27%"><input type="checkbox" name="Information_on[]" value="Rapid Auto Roll Doors" id="Information on" />
Rapid Auto Roll Doors<br />
<input type="checkbox" name="Information_on[]" value="Swingflex Doors" id="Information on" />
Swingflex Doors<br />
<input type="checkbox" name="Information_on[]" value="Floor Guides" id="Information on" />
Floor Guides<br />
<input type="checkbox" name="Information_on[]" value="Visiflex Strip Doors" id="Information on" />
Visiflex Strip Doors<br />
<input type="checkbox" name="Information_on[]" value="PVC-Strip / Sheets" id="Information on" />
PVC-Strips / Sheets</td>
<td width="37%"><input type="checkbox" name="Information_on[]" value="Efaflex Doors" id="Information on" />
Efaflex Doors <br />
<input type="checkbox" name="Information_on[]" value="Traffic Doors" id="Information on" />
Traffic Doors<br />
<input type="checkbox" name="Information_on[]" value="Fold Up Doors" id="Information on" />
Fold Up Doors <br />
<input type="checkbox" name="Information_on[]" value="Dock Levellers" id="Information on" />
Dock Levellers<br />
<input type="checkbox" name="Information_on[]" value="Other" id="Information on" />
Other
</p></td>
它们都有相同的名称:Information_on[]
ok所以下一部分是将“选定的”转换为一个类似于以下格式的 php 字符串:
$outputExample = "selecteditem1, selecteditem2, selecteditem3.";
但当然是在复选框中设置的值。
所以我不知道该怎么做,收集它们并检查哪些标题需要用 PHP 发送...感谢您的帮助!
Ok so I am making an emailing form and need to get a bunch of items in a checkbox array to be printed... or converted into a string... so they can be made into a variable...
here is what the form looks like:
And there is the html behind it:
<th valign="top" scope="row">Receive further information_on: </th>
<td width="27%"><input type="checkbox" name="Information_on[]" value="Rapid Auto Roll Doors" id="Information on" />
Rapid Auto Roll Doors<br />
<input type="checkbox" name="Information_on[]" value="Swingflex Doors" id="Information on" />
Swingflex Doors<br />
<input type="checkbox" name="Information_on[]" value="Floor Guides" id="Information on" />
Floor Guides<br />
<input type="checkbox" name="Information_on[]" value="Visiflex Strip Doors" id="Information on" />
Visiflex Strip Doors<br />
<input type="checkbox" name="Information_on[]" value="PVC-Strip / Sheets" id="Information on" />
PVC-Strips / Sheets</td>
<td width="37%"><input type="checkbox" name="Information_on[]" value="Efaflex Doors" id="Information on" />
Efaflex Doors <br />
<input type="checkbox" name="Information_on[]" value="Traffic Doors" id="Information on" />
Traffic Doors<br />
<input type="checkbox" name="Information_on[]" value="Fold Up Doors" id="Information on" />
Fold Up Doors <br />
<input type="checkbox" name="Information_on[]" value="Dock Levellers" id="Information on" />
Dock Levellers<br />
<input type="checkbox" name="Information_on[]" value="Other" id="Information on" />
Other
</p></td>
they all have the same name: Information_on[]
ok so the next part is to convert the "selected" ones into a php string that would look like the following format:
$outputExample = "selecteditem1, selecteditem2, selecteditem3.";
but of course with the values set in the checkboxes.
So I have no idea how to do this, to have them be gathered and checked to see which titles need to be sent in PHP... thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您的表单是 POST,因为您正在制作联系表单。然后你可以这样做:
记住,如果复选框为空,你将不会在 $_POST 数组中获得任何值(甚至不是“off” - 只是它的工作方式!)。
Make sure your form is POST, since you're making a contact form. Then you could do something like this:
Remember that where a checkbox is blank, you won't get any value in your $_POST array (not even an "off" - just the way it works!).
请记住始终清理您的数据输入!
Remember to always sanitize your data inputs!