doxd96148 2012-12-15 10:33
浏览 51

联系表单组复选框数组

I have a contact form built with PHP and I had a radio option box (one click) and have changed it to a group check box, which means multiple boxes can be clicked.

However, only the last most click is sent through to my email and playing with the code has messed me up, I am not very clear with the php array code and multiple (({{

Here is the html code

    <label><input type="checkbox" name="addon" value="NONE" <?php if (isset($_POST['addon']) && $_POST['addon'] == 'NONE') echo 'checked="checked"'; ?> tabindex="4" />  None <br /></label>
    <label><input type="checkbox" name="addon" value="HKG" <?php if (isset($_POST['addon']) && $_POST['addon'] == 'HKG') echo 'checked="checked"'; ?> tabindex="5" />  Hong Kong <br /></label>
    ....
    <label><input type="checkbox" name="addon" value="Other Start City" <?php if (isset($_POST['trip']) && $_POST['addon'] == 'Other Start City') echo 'checked="checked"'; ?> tabindex="4" /> Other</label>

and here is the php code I have at the moment, but this only gives one answer.

    $Indhold .= "Tour Extension: ".$_POST['addon']."
";

I tried changing it to an array (as I followed the tutorial http://www.html-form-guide.com/php-form/php-form-checkbox.html) , but then only array was printed on the email.

I also want to include validation on that combi box, if possible. So they can't choose NONE and HKG, and must click at least one.

  • 写回答

3条回答 默认 最新

  • dongliang1223 2012-12-15 10:35
    关注

    PHP only populates $_POST/GET with arrays if the name ends in [] (or [index]).

    Use name="addon[]"

    Arrays aren't strings, so you can't just concatenate them. You can use implode to convert the members of an array into a single string. You could also use a for loop to deal with them one by one.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值