处理 php 中的复选框数组

发布于 2024-12-07 18:20:52 字数 1868 浏览 0 评论 0原文

好的,我正在制作一个电子邮件表单,需要在复选框数组中获取一堆要打印的项目...或转换为字符串...这样它们就可以变成变量...

这就是表单的内容看起来像:

在此处输入图像描述

它后面有 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执妄 2024-12-14 18:20:52

确保您的表单是 POST,因为您正在制作联系表单。然后你可以这样做:

$info = $_POST['Information_on'];
$outputExample = implode(', ', $info);

记住,如果复选框为空,你将不会在 $_POST 数组中获得任何值(甚至不是“off” - 只是它的工作方式!)。

Make sure your form is POST, since you're making a contact form. Then you could do something like this:

$info = $_POST['Information_on'];
$outputExample = implode(', ', $info);

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!).

我也只是我 2024-12-14 18:20:52

请记住始终清理您的数据输入!

$info = filter_var_array($_POST['Information_on'], FILTER_SANITIZE_STRING);
$CSV = implode(', ', $info)

Remember to always sanitize your data inputs!

$info = filter_var_array($_POST['Information_on'], FILTER_SANITIZE_STRING);
$CSV = implode(', ', $info)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文