Bethfiander Bethfiander - 1 year ago 67
PHP Question

Checkbox Send Multiple Options in Form

Having an issue with receiving multiple options.

I have a form and I have just implemented a checkbox into my html:

<input type="checkbox" name="bookingoptions" value="1">
<input type="checkbox" name="bookingoptions" value="2">
<input type="checkbox" name="bookingoptions" value="3">

At the moment the form uses send_booking_email.php.

<form id="booking-form" form name="bookingform" method="post" action="send_booking_email.php">

Within send_booking_email.php:


if(isset($_POST['email'])) {

$email_to = "";

// validation expected data exists

if(!isset($_POST['bookingoptions'])) {


$bookingoptions = $_POST['bookingoptions']; // required

$email_message .= "Booking Options:".clean_string($bookingoptions)."\n";

// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);





This works fine when one option is selected, however I am unable to get it to send multiple selections.

I believe it is due to:

$email_message .= "Booking Options:".clean_string($bookingoptions)."\n";

Being only able to store one value? If so is there a way around this?

Thanks in advance!

ubm ubm
Answer Source
<input type="checkbox" name="bookingoptions_1" value="1">  
<input type="checkbox" name="bookingoptions_2" value="2">          
<input type="checkbox" name="bookingoptions_3" value="3">

then next php side


 while (isset($_POST['bookingoptions_' . $x])) {

        $bookingoptions .=$_POST['bookingoptions_' . $x];
     $bookingoptions .=','.$_POST['bookingoptions_' . $x];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download