Implode array for PHP checkbox in Form

给你一囗甜甜゛ 提交于 2019-12-02 09:13:18
Khushboo

Try :-

$check_msg = implode(", ", $_POST['check']);

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!