0

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>
1
  • 1
    What's the problem? What's not working? Commented Sep 19, 2014 at 11:42

2 Answers 2

4

Try :-

$check_msg = implode(", ", $_POST['check']);
Sign up to request clarification or add additional context in comments.

1 Comment

Background: $_POST['check'] is an array. HTML's input field with a name that contains brackets creates an array.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.