douyuanqia665858 2017-05-04 06:58
浏览 151
已采纳

$ _POST不会发送空复选框组

I have been working on a contact form for a website and I got this problem: I have 4 checkboxgroups, every each of them have at least 3 checkboxes that are available to check. We don't want them to be required to send the email. So the code is this:

$CheckboxGroup1 = array();
if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $attending = $_POST['attending'];
    $CheckboxGroup1 = isset($_POST['CheckboxGroup1']) ? $_POST['CheckboxGroup1'] : 'Nothing checked';

HTML:

 <h4>What kind of set-up would you like?</h4>
 <p>Additional fees may apply for living room/specialty set-ups.</p>
 <p>
     <div class="inline-field">
         <label>
             <input type="checkbox" name="CheckboxGroup1[]" value="Living Room">
            Living Room
        </label>
        <br>
        <label>
            <input type="checkbox" name="CheckboxGroup1[]" value="Conference Room">
            Conference Room
        </label>
        <br>
        <label>
            <input type="checkbox" name="CheckboxGroup1[]" value="Other">
            Other (please specify at the end of the form)
        </label>
        <br>
    </div>
</p>

When none of the checkboxes is selected I get the message "Nothing checked" and when one of them is selected I get the value of it. The problem is when I select more than one, I get this in my email: What kind of set-up will you like?: Array (not the name of those selected).

I do not know what I have to change to make it work the right way.

Any help would be very much appreciated.

  • 写回答

2条回答 默认 最新

  • dpoxk64080 2017-05-04 07:08
    关注

    you have to change below line

    Your code

    $CheckboxGroup1 = isset($_POST['CheckboxGroup1']) ? $_POST['CheckboxGroup1'] :  'Nothing checked';
    

    Change it to

    if( isset($_POST['CheckboxGroup1']))
    {
     $CheckboxGroup1 =implode(", ",$_POST['CheckboxGroup1']);
    }
    else{
      $CheckboxGroup1="Nothing checked";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本