I apologize if it is stupid question. I wanted to check whether one or more checkboxes are not empty, then can process the form and print interest text for email.
HTML/PHP
<p><label for="commentsText">I am interested in:</label><br/>
<input type="checkbox" name="interest[]" id="interest" value="1" class="required requiredField email" />
Exhibiting. Please send me more information<br/>
<input type="checkbox" name="interest[]" id="interest" value="2" class="required requiredField email" />
Visiting. Please add me to your mailing list<br/>
<input type="checkbox" name="interest[]" id="interest" value="3" class="required requiredField email" />
Speaking. Please send me more information<br/>
<input type="checkbox" name="interest[]" id="interest" value="4" class="required requiredField email" />
Attending. Please send me more information<br/>
<?php if($interestError != '') { ?>
<span class="error"><?php echo $interestError; ?></span>
<?php } ?>
</p>
PHP
$interest='';
if(empty($_POST[$interest]))
{
$interestError ='Please select the interests';
$hasError = true;
}
else{
$numberofInterest = count($interest);
for ($i=0; $i < $numberofInterest; $i++)
{
$numofInterest = $interest[i];
echo $numofInterest . " ";
}
}
EDIT #2
Thank you everybody for the help. I used print_r and saw all four are printed. The problem is now: if no error, send mail. It doesn't show all when I checked all checkboxes. Only displays '4'. Is there a way to display all including texts?
if(!isset($hasError)) {
$interest = $numofInterest ;
$subject = 'I Have A Question to Ask from '.$name;
$thanksubject = 'Thank you for the Form Submission';
$body = "Name: $name \n\nEmail: $email \n\nInterest: $interest\n\nComments: $comments";
*EDIT #3*
OK I have solved that last one above. managed to send email with everything.