user2124473
user2124473

Reputation: 1

group check box in php and send to email

I am using a sample php conatct form from http://www.html-form-guide.com/contact-form/php-contact-form-tutorial.html and I want to use check box in my form , but I am receiving only last checked one in my email. I find out that I should use array for check boxes like:

input type="checkbox" name="chk_group[]" value="value1" />Value 1<br />
input type="checkbox" name="chk_group[]" value="value2" />Value 2<br />
input type="checkbox" name="chk_group[]" value="value3" />Value 3<br />

and I should use following loop some where in my code:

<?php
if (isset($_POST['chk_group'])) {
    $optionArray = $_POST['chk_group'];
    for ($i=0; $i'<'count($optionArray); $i++) {
        echo $optionArray[$i]."<br />";
    }
}
?>

Unfortunately I tried but because the sample contact form which I am using is a little bit strange for me I got errors.

I appreciate if some one can help me to solve this problem. Thanks

Upvotes: 0

Views: 171

Answers (1)

Jocelyn
Jocelyn

Reputation: 11393

Remove the single quotes around <. It should be:

for ($i=0; $i<count($optionArray); $i++) {

You may also replace the for loop with a foreach loop:

foreach($optionArray as $element) {
    echo $element."<br />";
}

Upvotes: 1

Related Questions