开发者

Php form checkboxes help (again)

开发者 https://www.devze.com 2023-01-26 09:26 出处:网络
sorry, I have another problem now. I\'m using a new php form method than I previously used. I have something like this:

sorry, I have another problem now. I'm using a new php form method than I previously used.

I have something like this:

<?php 
$ToEmail = 'bryan@email.com'; 
$subject = 'Contact Form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$message = "Name: ".$_POST["name"]."<br>"; 
$message .= "Subject: ".$_POST["subject"]."<br>"; 
$message .= "Email: ".$_POST["email"]."<br>"; 
$message .= "Message: ".nl2br($_POST["message"])."<br>"; 
mail($ToEmail, $subject, $message, $mailheader) or die ("Failure"); 

but I need to include check boxes. I originally had: $check .= implode(', ', $_POST['check']); from someone else on here but that doesn't work now and not sure what else to do for this. Any help would be appreciated!

the开发者_如何转开发 page is located here: http://makeupbysherry.com/contact.php


Checkboxes only post a true or false value if they're checked or not. I would suggest breaking up each of your checkboxes with unique names then checking their post values.

input name="chk-makeover" value="Makeover" type="checkbox" class="contact_checkbox"

To include the example checkbox above in your message you can try the following:

$message .= "Services: ";
if (isset($_POST['chk-makeover'])) $message .= "Makeover";


You want to append the selected boxes onto your message?

Your $check .= implode(', ', $_POST['check']) should work, all you have to do to that is append it to the message afterwards.

So:

<?php 
$ToEmail = 'bryan@email.com'; 
$subject = 'Contact Form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$message = "Name: ".$_POST["name"]."<br>"; 
$message .= "Subject: ".$_POST["subject"]."<br>"; 
$message .= "Email: ".$_POST["email"]."<br>"; 
$message .= "Message: ".nl2br($_POST["message"])."<br>";

if(isset($_POST['check'])){
    $message .= implode(', ', $_POST['check']);
}

mail($ToEmail, $subject, $message, $mailheader) or die ("Failure"); 

Edit: Forgot the check to see if the check array that's sent through POST is set or not. See revised ^^

Edit2: Actually, there'll be a problem if the $_POST['check'] doesn't exist as we are still appending from $check that doesn't have anything on the next line so, so it's better to append it to $message right from the start. Last revision lol. Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消