Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 code I need to add and where? Thanks!

CODE IN PHP:

    $to='[email protected]';
    $subject='Enquiry - Contact Page';

    $name_field = $_POST['firstname'];
    $secondname_field = $_POST['lastname'];
    $email_field = $_POST['email'];
    $phone_field = $_POST['phone'];
    $dropdown = $_POST['drop_down'];
    $message = $_POST['message'];
    $check_msg = $_POST['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;      

    mail($to,$subject,$body);
    echo '  ';

    ?>

CODE IN .HTML

            <form method="post" action="contactform.php">
                        <input name="firstname" type="text" value="First Name" class="form2"/><br/>
                        <input name="lastname" type="text" value="Last Name" class="form2"/><br/>
                        <input name="email" type="text" value="Email" class="form2"/>   <br/>
                        <input name="phone" type="text" value="Phone" class="form2"/>   
                        <br />
                        <select name="drop_down" class="form2">
                        <option selected="selected">Prefered contact method
                        </option>
                        <option>Phone</option>
                        <option>Email</option>
                        </select><br />
                        <textarea name="message" cols="30" rows="5" class="form2">About your project..</textarea> 
                        <br />
                        <span class="form">
                        I am looking for...<br /> 
                        <input name="check[]" type="checkbox" value="New-Website" />A new website<br/>
                        <input name="check[]" type="checkbox" value="Existing-Website" />Upgrade an exsiting website<br/>
                        <input name="check[]" type="checkbox" value="Online-Store"/>Online Store<br/>
                        <input name="check[]" type="checkbox" value="Graphic-Design"/>Graphic and logo design<br/>
                        <input name="check[]" type="checkbox" value="Other"/>Other<br/>
                        <br />                  
                        </span>
                        <input name="Submit" type="submit" value="submit" class="form"/>
                    </form>
share|improve this question
1  
What's the problem? What's not working? –  Dan Sep 19 at 11:42

2 Answers 2

up vote 3 down vote accepted

Try :-

$check_msg = implode(", ", $_POST['check']);
share|improve this answer
1  
Background: $_POST['check'] is an array. HTML's input field with a name that contains brackets creates an array. –  Zim84 Sep 19 at 11:46

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.