Jump to content


Photo

checkbox arrays


  • Please log in to reply
5 replies to this topic

#1 kwijmbo

kwijmbo
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 May 2006 - 07:28 AM

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.*******.c...om/booking.htm" ;
$errorurl = "http://www.********.....com/error.htm" ;
$thankyouurl = "http://www.*******.c...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

#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 31 May 2006 - 07:36 AM

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 :
$treatmentString = implode(",",$treatment);


#3 kwijmbo

kwijmbo
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 May 2006 - 07:42 AM

soo....how do i make it work how i want it too?

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 01:55 PM

Change:

$treatment = $_POST['treatment'];
$day = $_POST['day'];
$time = $_POST['time'];
To
$treatment = implode(', ', $_POST['treatment']);
$day = implode(', ', $_POST['day']);
$time = implode(', ', $_POST['time']);

~ D Kuang

#5 kwijmbo

kwijmbo
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 May 2006 - 11:40 PM


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?

#6 kwijmbo

kwijmbo
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 June 2006 - 12:05 AM

bump




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users