Jump to content

Archived

This topic is now archived and is closed to further replies.

kwijmbo

checkbox arrays

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

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

×

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.