kwijmbo Posted May 31, 2006 Share Posted May 31, 2006 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: ArrayDay: ArrayTime: ArrayCan someone please help me as i'm realllly frustrated with this.CheersPaul Quote Link to comment https://forums.phpfreaks.com/topic/10829-checkbox-arrays/ Share on other sites More sharing options...
KrisNz Posted May 31, 2006 Share Posted May 31, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10829-checkbox-arrays/#findComment-40475 Share on other sites More sharing options...
kwijmbo Posted May 31, 2006 Author Share Posted May 31, 2006 soo....how do i make it work how i want it too? Quote Link to comment https://forums.phpfreaks.com/topic/10829-checkbox-arrays/#findComment-40478 Share on other sites More sharing options...
poirot Posted May 31, 2006 Share Posted May 31, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10829-checkbox-arrays/#findComment-40560 Share on other sites More sharing options...
kwijmbo Posted May 31, 2006 Author Share Posted May 31, 2006 Warning: implode() [function.implode]: Bad arguments. in /home/smile/public_html/booking.php on line 78Warning: implode() [function.implode]: Bad arguments. in /home/smile/public_html/booking.php on line 79Warning: implode() [function.implode]: Bad arguments. in /home/smile/public_html/booking.php on line 80Warning: 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 89changed the code as you prescribed...but got this error - any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/10829-checkbox-arrays/#findComment-40732 Share on other sites More sharing options...
kwijmbo Posted June 5, 2006 Author Share Posted June 5, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/10829-checkbox-arrays/#findComment-41900 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.