0

I'm trying to feed the following checkboxes through to a PHP email form:

<div id="product_information_container">
    <h1 id="product_information_subtitle"><a data-tooltip="Click to hide/display the content below." href="#"><img class="information_icons" src="images/information_icon.png"></a>What can we help you with?</h1>
    <div class="product_information">
        <div class="product_information_containers" id="product_information_attic_barrier">
            <input id="product_information_checkbox_attic_barrier" name="product_information[]" type="checkbox" value="attic_barrier" />
            <span class="product_options">Attic Barrier</span>
        </div>
    </div>
    <div class="product_information">
        <div class="product_information_containers" id="product_information_doors">
            <input id="product_information_checkbox_doors" name="product_information[]" type="checkbox" value="entry_system_door" />
            <span class="product_options">Entry System Door</span>
        </div>
    </div>
    <div class="product_information">
        <div class="product_information_containers" id="product_information_eavestrough_cover">
            <input id="product_information_checkbox_eavestrough_cover" name="product_information[]" type="checkbox" value="eavestrough_cover" />
            <span class="product_options">Eavestrough Cover</span>
        </div>
    </div>
    <div class="product_information">
        <div class="product_information_containers" id="product_information_windows">
            <input id="product_information_checkbox_windows" name="product_information[]" type="checkbox" value="windows" />
            <span class="product_options">Windows</span>
        </div>
    </div>
    <div class="product_information" id="window_options">
        <div id="windows_options_one">
            <div class="product_information_windows_containers" id="product_information_windows_baybow">
                <input id="windows_baybow_checkbox" name="product_information[]" type="checkbox" value="windows" />
                <span class="product_options">Bay/Bow</span>
            </div>
            <div class="product_information_windows_containers" id="product_information_windows_casement">
                <input id="windows_casement_checkbox" name="product_information[]" type="checkbox" value="windows" />
                <span class="product_options">Casement</span>
            </div>
        </div>
        <div id="windows_options_two">
            <div class="product_information_windows_containers" id="product_information_windows_doublehung">
                <input id="windows_doublehung_checkbox" name="product_information[]" type="checkbox" value="windows" />
                <span class="product_options">Double-Hung</span>
            </div>
            <div class="product_information_windows_containers" id="product_information_windows_sliding">
                <input id="windows_sliding_checkbox" name="product_information[]" type="checkbox" value="windows" />
                <span class="product_options">Sliding</span>
            </div>
        </div>
    </div>
</div>

I then intend to capture the information entered, and notify which pieces of information are relevant. Essentially, all products selected within "product_information" should be fed through, if checked. However, with my current code, I only receive the last value selected in the group of checkboxes.

Here is my PHP code:

<?php  
if(isset($_POST)){
    $ip_address = $_SERVER['REMOTE_ADDR'];
    $date = date('d/m/Y');
    $time = date('H:i:s');

    $first_name = $_POST['first_name'];
    $spouse_name = $_POST['spouse_name'];
    $last_name = $_POST['last_name'];
    $street_number = $_POST['street_number'];
    $street_name = $_POST['street_name'];
    $street_type = $_POST['street_type'];
    $city = $_POST['city'];
    $postal_code = $_POST['postal_code'];
    $phone_number = $_POST['phone_number'];
    $alternate_phone_number = $_POST['alternate_phone_number'];
    $email_address = $_POST['email_address'];
    $contact_time = $_POST['contact_time'];
    $product_information = $_POST['product_information'];

    $headers = "From: [email protected]" . "\r\n";  
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

    $emailbody = "<p>You have received a message!</p> 
                  <strong>Name: </strong>{$first_name} {$last_name}, <strong>Spouse's Name: </strong>{$spouse_name}<br />
                  <strong>Address: </strong>{$street_number} {$street_name} {$street_type}, {$city}, ON {$postal_code}<br />
                  <strong>Phone Number: </strong> {$phone_number}, <strong>Alt. Phone Number: </strong> {$alternate_phone_number}<br />
                  <strong>Email Address: </strong> {$email_address}</p>
                  <p>Please contact {$first_name} during the {$contact_time} about {$product_information}.<br
                  <p>This message was sent from the IP Address: {$ip_address} on {$date} at {$time}.</p>";  

    mail('[email protected]','Title',$emailbody,$headers);
}
?>
3
  • The value of $_POST['product_information'] should be an array. I find it hard to believe that your output is the last value selected in the group of checkboxes and not Array. Commented Aug 14, 2012 at 5:51
  • All your checkbox values have the same value of windows. What is up with that? Commented Aug 14, 2012 at 5:55
  • Here is what I select: imageshack.us/f/26/beforese.jpg Here is what I get: imageshack.us/f/855/resultsv.jpg Commented Aug 14, 2012 at 14:50

2 Answers 2

1

$_POST['product_information'] is an array, maybe you will find useful implode function to concatonate all values with separator:

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

Comments

0

Each checkbox needs its own value but on Windows, Bay/Bow, Casement, Double-Hung, Sliding they are all value="windows" so if all of them were checked you would get the array

Array ( [product_information] => Array ( [0] => windows
                                         [1] => windows
                                         [2] => windows
                                         [3] => windows
                                         [4] => windows ) )`

Change to something like-

<div class="product_information">
    <div class="product_information_containers" id="product_information_windows">
        <input id="product_information_checkbox_windows" name="product_information[]" type="checkbox" value="windows" />
        <span class="product_options">Windows</span>
    </div>
</div>
<div class="product_information" id="window_options">
    <div id="windows_options_one">
        <div class="product_information_windows_containers" id="product_information_windows_baybow">
            <input id="windows_baybow_checkbox" name="product_information[]" type="checkbox" value="baybow" />
            <span class="product_options">Bay/Bow</span>
        </div>
        <div class="product_information_windows_containers" id="product_information_windows_casement">
            <input id="windows_casement_checkbox" name="product_information[]" type="checkbox" value="casement" />
            <span class="product_options">Casement</span>
        </div>
    </div>
    <div id="windows_options_two">
        <div class="product_information_windows_containers" id="product_information_windows_doublehung">
            <input id="windows_doublehung_checkbox" name="product_information[]" type="checkbox" value="doublehung" />
            <span class="product_options">Double-Hung</span>
        </div>
        <div class="product_information_windows_containers" id="product_information_windows_sliding">
            <input id="windows_sliding_checkbox" name="product_information[]" type="checkbox" value="sliding" />
            <span class="product_options">Sliding</span>
        </div>
    </div>
</div>

Now you will have a proper array

Array ( [product_information] => Array ( [0] => windows 
                                         [1] => baybow 
                                         [2] => casement 
                                         [3] => doublehung 
                                         [4] => sliding ))

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.