Implode array for PHP checkbox in Form

后端 未结 2 1448
Happy的楠姐
Happy的楠姐 2021-01-26 08:20

I have looked at multiple examples of the implode array and cannot work out why I cannot see if multiple check boxes are selected.

Can I pleas get assistance as to what

相关标签:
2条回答
  • 2021-01-26 08:48

    Try :-

    $check_msg = implode(", ", $_POST['check']);
    
    0 讨论(0)
  • 2021-01-26 08:48

    If you're using <input name="check[]" type="checkbox" />, you'll already get an array in $_POST['check']. You're having an error because you're trying to concatenate an array $check_msg in a string $body.

    You need to do the following:

    $check = isset($_POST['check']) ? $_POST['check'] : '';
    $check_msg = is_array($check) ? implode(", ", $check) : '';
    $body = "F-Name: ".$name_field ."\r\n". "L-Name: ".$secondname_field ."\r\n". "Email: ".$email_field ."\r\n". "Phone: ".$phone_field ."\r\n". "Contact-Method: ".$dropdown ."\r\n". "Message: ".$message ."\r\n". $check_msg;      
    

    If $_POST['check'] isn't an array, you won't get a PHP error.

    0 讨论(0)
提交回复
热议问题