0

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:

<?php


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


    $email_to = "[email protected]";

    // 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);  

?>


<?php

}

?>

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!

0

3 Answers 3

4

Rename this field to bookingoptions[] and you will get array for $_POST['bookingoptions']

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

then implode array elements into string:

clean_string(implode(', ', $bookingoptions))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot for your help... Working now!
1
<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

$x=1;
$bookingoptions="";


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

     if($x==1)
     {
        $bookingoptions .=$_POST['bookingoptions_' . $x];
     }
     else
        {
     $bookingoptions .=','.$_POST['bookingoptions_' . $x];
 }

    $x++;
 }

Comments

0

Send the POST request as an array of booking options like this:

<input type="checkbox" name="bookingoptions[]" value="1">

Do this for all the input tags with name bookingoptions replacing bookingoptions to bookingoptions[]

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.