Jump to content

checkbox arrays


kwijmbo

Recommended Posts

I have built a form with a section in it including checkboxes and radio buttons.

The form's results are to be mailed to an email address. the problem i'm having is i'm only new to php and a lof of guides on the net refer to echoing data rather than mailing it. that and its very confusing to me.

I have managed to get the form working for all information except the checkboxes and radio buttons.

I have attempted to create an array in my html form. here's an extract:

<input name="day[]" type="checkbox" id="day[]" value="Monday">
<input name="day[]" type="checkbox" id="day[]" value="Tuesday">
<input name="day[]" type="checkbox" id="day[]" value="Wednesday">


And the php is as follows

$mailto = 'info@******.com' ;
$subject = "Website Booking Enquiry" ;
$formurl = "http://www.*******.com/booking.htm" ;
$errorurl = "http://www.********.com/error.htm" ;
$thankyouurl = "http://www.*******.com/thanks.htm" ;

$uself = 0;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$email = $_POST['email'] ;
$treatment = $_POST['treatment'] ;
$day = $_POST['day'] ;
$time = $_POST['time'] ;

$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['name'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($phone) || empty($email)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $phone) ) {
header( "Location: $errorurl" );
exit ;
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n\n" .
"CONTACT DETAILS ----------------------------\n" .
"Name: $name\n" .
"Phone: $phone\n" .
"Email: $email\n\n" .
"BOOKING DETAILS ----------------------------\n" .
"Treatment: $treatment\n" .
"Day: $day\n" .
"Time: $time\n" .
"---------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"Bookinh Enquiry \"" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>


I played around with the [] brackets in the php code but when any box is ticked, its loads in my email with the value "Array"

eg.

BOOKING DETAILS------------------
Treatment: Array
Day: Array
Time: Array

Can someone please help me as i'm realllly frustrated with this.

Cheers
Paul
Link to comment
Share on other sites

thats because those variables ARE arrays. Say for example you wanted to turn that array into a comma delimited string you could use the implode function : [code]$treatmentString = implode(",",$treatment);[/code]
Link to comment
Share on other sites

Change:

[code]$treatment = $_POST['treatment'];
$day = $_POST['day'];
$time = $_POST['time'];[/code]
To
[code]$treatment = implode(', ', $_POST['treatment']);
$day = implode(', ', $_POST['day']);
$time = implode(', ', $_POST['time']);[/code]
Link to comment
Share on other sites


Warning: implode() [function.implode]: Bad arguments. in /home/smile/public_html/booking.php on line 78

Warning: implode() [function.implode]: Bad arguments. in /home/smile/public_html/booking.php on line 79

Warning: implode() [function.implode]: Bad arguments. in /home/smile/public_html/booking.php on line 80

Warning: Cannot modify header information - headers already sent by (output started at /home/smile/public_html/booking.php:78) in /home/smile/public_html/booking.php on line 89

changed the code as you prescribed...but got this error - any ideas?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.