I have a form with a group of checkboxes that when I post to the database, the responses are not being captured. Error reporting is not showing anything and the field is blank.
The odd thing I find is that I have a second checkbox group setup exactly the same that does post.
The database field is:
name: LAB_Results
type: text
My form group is:
<div class="form-row">
<div class="col-lg-4 mb-2">
<label > 3. LABORATORY RESULTS: within the past 6 months (please submit the results)</label>
</div>
<div class="col-lg-8 mb-2">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="LAB_Results[]" name="LAB_Results[]" value="Chemistry Profile">
<label class="form-check-label" >Chemistry Profile</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="LAB_Results[]" id="Lab_Results[]" value="CBC">
<label class="form-check-label" >Complete Blood Count</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="LAB_Results[]" id="Lab_Results[]" value="Urinalysis">
<label class="form-check-label" >Urinalysis</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="LAB_Results[]" id="Lab_Results[]" value="Urine Culture & Susceptibility">
<label class="form-check-label" >Urine Culture & Susceptibility</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="LAB_Results[]" id="Lab_Results[]" value="Skin Bacterial Culture & Susceptibility">
<label class="form-check-label" >Skin Bacterial Culture & Susceptibility</label>
</div>
<div class="form-check form-check-inline">
<label class="form-check-label" >Other Test(s)</label>
<input class="form-check-input" type="text" id="Lab_Results[]" name="LAB_Results[]" placeholder="Other Test(s)">
</div>
</li>
</ul>
</div>
</div>
</div><!-- end of card div -->
My post script is:
<?PHP
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*** THIS! ***/
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("information removed");
if (mysqli_connect_error()) { echo mysqli_connect_error(); exit; }
if (isset($_POST['submit'])){
// The (?,?,?) below are parameter markers used for variable binding
$sql = "INSERT INTO tbl_dermatology_form_rdvm (date_submitted, UMNCaseNo, ClientName, ClientPhone, Pet_Name, Species, Breed, rDVM_Clinic, rDVM, Reason_for_Referral, Relevant_History, Relevant_Clinical_Signs, Pruritus_Present, Photos_Available, Photos_Submitted, Skin_Scrapings, Skin_Scrapings_Results, Ear_Cytology, Ear_Cytology_Results, Skin_Cytology, Skin_Cytology_Results, Fungal_Culture, Fungal_Culture_Results, FNA, FNA_Results, Biopsy, Biopsy_Results, Other_Test, Other_Test_Results, Allergy_Test, Allergy_Test_Date, Food_Trial, Food_Trial_Diet, Food_Trial_Duration, Food_Trial_Response, LAB_Results, P_Tx_1, P_Tx_1_Response, P_Tx_2, P_Tx_2_Response, P_Tx_3, P_Tx_3_Response, P_Tx_4, P_Tx_4_Response, P_Tx_5, P_Tx_5_Response, C_Tx_1, C_Tx_1_Response, C_Tx_2, C_Tx_2_Response, C_Tx_3, C_Tx_3_Response, C_Tx_4, C_Tx_4_Response, C_Tx_5, C_Tx_5_Response, Additional_Care, Unrelated_Services, Comments_Special_Requests, rDVM_email, Vet_Visit_Behavior, Client_Patient_Concerns
) VALUES (NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", $UMNCaseNo, $ClientName, $ClientPhone, $Pet_Name, $Species, $Breed, $rDVM_Clinic, $rDVM, $Reason_for_Referral, $Relevant_History, $Relevant_Clinical_Signs, $Pruritus_Present, $Photos_Available, $Photos_Submitted, $Skin_Scrapings, $Skin_Scrapings_Results, $Ear_Cytology, $Ear_Cytology_Results, $Skin_Cytology, $Skin_Cytology_Results, $Fungal_Culture, $Fungal_Culture_Results, $FNA, $FNA_Results, $Biopsy, $Biopsy_Results, $Other_Test, $Other_Test_Results, $Allergy_Test, $Allergy_Test_Date, $Food_Trial, $Food_Trial_Diet, $Food_Trial_Duration, $Food_Trial_Response, $LAB_Results, $P_Tx_1, $P_Tx_1_Response, $P_Tx_2, $P_Tx_2_Response, $P_Tx_3, $P_Tx_3_Response, $P_Tx_4, $P_Tx_4_Response, $P_Tx_5, $P_Tx_5_Response, $C_Tx_1, $C_Tx_1_Response, $C_Tx_2, $C_Tx_2_Response, $C_Tx_3, $C_Tx_3_Response, $C_Tx_4, $C_Tx_4_Response, $C_Tx_5, $C_Tx_5_Response, $Additional_Care, $Unrelated_Services, $Comments_Special_Requests, $rDVM_email, $Vet_Visit_Behavior, $Client_Patient_Concerns ); // bind variables
// Patient UMN Case Number
if (trim($_POST['UMNCaseNo']) == '') {
$UMNCaseNo = NULL;
} else {
$UMNCaseNo = trim($_POST['UMNCaseNo']);
}
// Client Name
if (trim($_POST['ClientName']) == '') {
$ClientName = NULL;
} else {
$ClientName = trim($_POST['ClientName']);
}
//Patient Name
if (trim($_POST['Pet_Name']) == '') {
$Pet_Name = NULL;
} else {
$Pet_Name = trim($_POST['Pet_Name']);
}
//Patient Species
if (trim($_POST['Species']) == '') {
$Species = NULL;
} else {
$Species = trim($_POST['Species']);
}
//Patient Breed
if (trim($_POST['Breed']) == '') {
$Breed = NULL;
} else {
$Breed = trim($_POST['Breed']);
}
//rDVM_Clinic
if (trim($_POST['rDVM_Clinic']) == '') {
$rDVM_Clinic = NULL;
} else {
$rDVM_Clinic = trim($_POST['rDVM_Clinic']);
}
//rDVM
if (trim($_POST['rDVM']) == '') {
$rDVM = NULL;
} else {
$rDVM = trim($_POST['rDVM']);
}
//Reason_for_Referral
if (trim($_POST['Reason_for_Referral']) == '') {
$Reason_for_Referral = NULL;
} else {
$Reason_for_Referral = trim($_POST['Reason_for_Referral']);
}
//Relevant_History
if(isset($_POST['Relevant_History']))
{
$Relevant_History = $_POST["Relevant_History"];
}
else {
$Relevant_History = NULL;
}
// Relevant_Clinical_Signs
if(isset($_POST['Relevant_Clinical_Signs']))
{
$Relevant_Clinical_Signs = $_POST["Relevant_Clinical_Signs"];
}
else {
$Relevant_Clinical_Signs = NULL;
}
// Pruritus_Present
if(isset($_POST['Pruritus_Present']))
{
$Pruritus_Present = $_POST["Pruritus_Present"];
}
else {
$Pruritus_Present = NULL;
}
// Photos_Available
if(isset($_POST['Photos_Available']))
{
$Photos_Available = $_POST["Photos_Available"];
}
else {
$Photos_Available = NULL;
}
// Photos_Submitted
if(isset($_POST['Photos_Submitted']))
{
$Photos_Submitted = $_POST["Photos_Submitted"];
}
else {
$Photos_Submitted = NULL;
}
// Skin_Scrapings
if(isset($_POST['Skin_Scrapings']))
{
$Skin_Scrapings = 'Y';
}
else {
$Skin_Scrapings = NULL;
}
// Skin_Scrapings_Results
if(isset($_POST['Skin_Scrapings_Results']))
{
$Skin_Scrapings_Results = $_POST["Skin_Scrapings_Results"];
}
else {
$Skin_Scrapings_Results = NULL;
}
// Ear_Cytology
if(isset($_POST['Ear_Cytology']))
{
$Ear_Cytology = 'Y';
}
else {
$Ear_Cytology = NULL;
}
// Ear_Cytology_Results
if(isset($_POST['Ear_Cytology_Results']))
{
$Ear_Cytology_Results = $_POST["Ear_Cytology_Results"];
}
else {
$Ear_Cytology_Results = NULL;
}
// Skin_Cytology
if(isset($_POST['Skin_Cytology']))
{
$Skin_Cytology = 'Y';
}
else {
$Skin_Cytology = NULL;
}
// Skin_Cytology_Results
if(isset($_POST['Skin_Cytology_Results']))
{
$Skin_Cytology_Results = $_POST["Skin_Cytology_Results"];
}
else {
$Skin_Cytology_Results = NULL;
}
// Fungal_Culture
if(isset($_POST['Fungal_Culture']))
{
$Fungal_Culture = 'Y';
}
else {
$Fungal_Culture = NULL;
}
// Fungal_Culture_Results
if(isset($_POST['Fungal_Culture_Results']))
{
$Fungal_Culture_Results = $_POST["Fungal_Culture_Results"];
}
else {
$Fungal_Culture_Results = NULL;
}
// FNA
if(isset($_POST['FNA']))
{
$FNA = 'Y';
}
else {
$FNA = NULL;
}
// FNA_Results
if(isset($_POST['FNA_Results']))
{
$FNA_Results = $_POST["FNA_Results"];
}
else {
$FNA_Results = NULL;
}
// Biopsy
if(isset($_POST['Biopsy']))
{
$Biopsy = 'Y';
}
else {
$Biopsy = NULL;
}
// Biopsy_Results
if(isset($_POST['Biopsy_Results']))
{
$Biopsy_Results = $_POST["Biopsy_Results"];
}
else {
$Biopsy_Results = NULL;
}
if(isset($_POST['Other_Test']))
{
$Other_Test = 'Y';
}
else {
$Other_Test = NULL;
}
// Other_Test_Results
if(isset($_POST['Other_Test_Results']))
{
$Other_Test_Results = $_POST["Other_Test_Results"];
}
else {
$Other_Test_Results = NULL;
}
// Allergy_Test
if(isset($_POST['Allergy_Test']))
{
$Allergy_Test = $_POST["Allergy_Test"];
}
else {
$Allergy_Test = NULL;
}
// Allergy_Test_Date
if(isset($_POST['Allergy_Test_Date']))
{
$Allergy_Test_Date = $_POST["Allergy_Test_Date"];
}
else {
$Allergy_Test_Date = NULL;
}
// Food_Trial
if(isset($_POST['Food_Trial']))
{
$Food_Trial = $_POST["Food_Trial"];
}
else {
$Food_Trial = NULL;
}
// Food_Trial_Diet
if(isset($_POST['Food_Trial_Diet']))
{
$Food_Trial_Diet = $_POST["Food_Trial_Diet"];
}
else {
$Food_Trial_Diet = NULL;
}
// Food_Trial_Duration
if(isset($_POST['Food_Trial_Duration']))
{
$Food_Trial_Duration = $_POST["Food_Trial_Duration"];
}
else {
$Food_Trial_Duration = NULL;
}
// Food_Trial_Response
if(isset($_POST['Food_Trial_Response']))
{
$Food_Trial_Response = $_POST["Food_Trial_Response"];
}
else {
$Food_Trial_Response = NULL;
}
// lab results
if(!empty($_POST['LAB_Results'])){
$Lab_Results = implode(', ', $_POST['LAB_Results']);
} else {
$Lab_Results = NULL;
}
// vet visit behavior
if(!empty($_POST['Vet_Visit_Behavior'])){
$Vet_Visit_Behavior = implode(', ', $_POST['Vet_Visit_Behavior']);
} else {
$Vet_Visit_Behavior = NULL;
}
// P_Tx_1
if(isset($_POST['P_Tx_1']))
{
$P_Tx_1 = $_POST["P_Tx_1"];
}
else {
$P_Tx_1 = NULL;
}
// P_Tx_1_Response
if(isset($_POST['P_Tx_1_Response']))
{
$P_Tx_1_Response = $_POST["P_Tx_1_Response"];
}
else {
$P_Tx_1_Response = NULL;
}
// P_Tx_2
if(isset($_POST['P_Tx_2']))
{
$P_Tx_2 = $_POST["P_Tx_2"];
}
else {
$P_Tx_2 = NULL;
}
// P_Tx_2_Response
if(isset($_POST['P_Tx_2_Response']))
{
$P_Tx_2_Response = $_POST["P_Tx_2_Response"];
}
else {
$P_Tx_2_Response = NULL;
}
// P_Tx_3
if(isset($_POST['P_Tx_3']))
{
$P_Tx_3 = $_POST["P_Tx_3"];
}
else {
$P_Tx_3 = NULL;
}
// P_Tx_3_Response
if(isset($_POST['P_Tx_3_Response']))
{
$P_Tx_3_Response = $_POST["P_Tx_3_Response"];
}
else {
$P_Tx_3_Response = NULL;
}
// P_Tx_4
if(isset($_POST['P_Tx_4']))
{
$P_Tx_4 = $_POST["P_Tx_4"];
}
else {
$P_Tx_4 = NULL;
}
// P_Tx_4_Response
if(isset($_POST['P_Tx_4_Response']))
{
$P_Tx_4_Response = $_POST["P_Tx_4_Response"];
}
else {
$P_Tx_4_Response = NULL;
}
// P_Tx_5
if(isset($_POST['P_Tx_5']))
{
$P_Tx_5 = $_POST["P_Tx_5"];
}
else {
$P_Tx_5 = NULL;
}
// P_Tx_5_Response
if(isset($_POST['P_Tx_5_Response']))
{
$P_Tx_5_Response = $_POST["P_Tx_5_Response"];
}
else {
$P_Tx_5_Response = NULL;
}
// C_Tx_1
if(isset($_POST['C_Tx_1']))
{
$C_Tx_1 = $_POST["C_Tx_1"];
}
else {
$C_Tx_1 = NULL;
}
// C_Tx_1_Response
if(isset($_POST['C_Tx_1_Response']))
{
$C_Tx_1_Response = $_POST["C_Tx_1_Response"];
}
else {
$C_Tx_1_Response = NULL;
}
// C_Tx_2
if(isset($_POST['C_Tx_2']))
{
$C_Tx_2 = $_POST["C_Tx_2"];
}
else {
$C_Tx_2 = NULL;
}
// C_Tx_2_Response
if(isset($_POST['C_Tx_2_Response']))
{
$C_Tx_2_Response = $_POST["C_Tx_2_Response"];
}
else {
$C_Tx_2_Response = NULL;
}
// C_Tx_3
if(isset($_POST['C_Tx_3']))
{
$C_Tx_3 = $_POST["C_Tx_3"];
}
else {
$C_Tx_3 = NULL;
}
// C_Tx_3_Response
if(isset($_POST['C_Tx_3_Response']))
{
$C_Tx_3_Response = $_POST["C_Tx_3_Response"];
}
else {
$C_Tx_3_Response = NULL;
}
// C_Tx_4
if(isset($_POST['C_Tx_4']))
{
$C_Tx_4 = $_POST["C_Tx_4"];
}
else {
$C_Tx_4 = NULL;
}
// C_Tx_4_Response
if(isset($_POST['C_Tx_4_Response']))
{
$C_Tx_4_Response = $_POST["C_Tx_4_Response"];
}
else {
$C_Tx_4_Response = NULL;
}
// C_Tx_5
if(isset($_POST['C_Tx_5']))
{
$C_Tx_5 = $_POST["C_Tx_5"];
}
else {
$C_Tx_5 = NULL;
}
// C_Tx_5_Response
if(isset($_POST['C_Tx_5_Response']))
{
$C_Tx_5_Response = $_POST["C_Tx_5_Response"];
}
else {
$C_Tx_5_Response = NULL;
}
// Additional_Care
if(isset($_POST['Additional_Care']))
{
$Additional_Care = $_POST["Additional_Care"];
}
else {
$Additional_Care = NULL;
}
// Unrelated_Services
if(isset($_POST['Unrelated_Services']))
{
$Unrelated_Services = $_POST["Unrelated_Services"];
}
else {
$Unrelated_Services = NULL;
}
// Comments_Special_Requests
if(isset($_POST['Comments_Special_Requests']))
{
$Comments_Special_Requests = trim($_POST["Comments_Special_Requests"]);
}
else {
$Comments_Special_Requests = NULL;
}
// rDVM email address
if(isset($_POST['rDVM_email'])) {
$rDVM_email = filter_var($_POST['rDVM_email'], FILTER_SANITIZE_EMAIL);
} else {
$rDVM_email = NULL;
}
// client or patient concerns
if(isset($_POST['Client_Patient_Concerns'])) {
$Client_Patient_Concerns = trim($_POST['Client_Patient_Concerns']);
} else {
$Client_Patient_Concerns = NULL;
}
if ($stmt->execute()) {
$last_id = $stmt->insert_id;
$headers = "From: " . strip_tags($email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body><h3>An rDVM Dermatology Questionnaire Has Been Submitted.</h3><br />';
$message .= "<br />";
$message .= "<br />";
$message .= "Thank you " .$rDVM ." for filling out the Dermatology form for " .$Pet_Name . " with, ". $ClientName . ". Your information has been received. If indicated, please use the following link <a href=".$url." target='_blank'>" .$url . "</a> to submit any photographs of your patients lesions or documents / test results. ";
$message .= "<br />";
$message .= "<br />";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'> <td width='178'></td> <td width='380'></td></tr>";
$message .= "<tr> <td><strong>Case/PA Number:</strong></td> <td>" . $UMNCaseNo . "</td></tr>";
$message .= "<tr><td colspan='2'> </td></tr>";
$message .= "<tr> <td><strong>Client Name:</strong> </td><td>" . $ClientName . "</td></tr>";
$message .= "<tr><td colspan='2'> </td></tr>";
$message .= "<tr><td><strong>Pet Name:</strong></td> <td>" . $Pet_Name . "</td></tr>";
$message .= "<tr><td><strong>Species:</strong></td> <td>" . $Species . "</td></tr>";
$message .= "<tr><td><strong>Breed:</strong></td> <td>" . $Breed . "</td></tr>";
$message .= "<tr><td colspan='2'> </td></tr>";
$message .= "<tr><td><strong>Clinic Name:</strong></td> <td>" . $rDVM_Clinic . "</td></tr>";
$message .= "<tr><td><strong>rDVM Name:</strong></td> <td>" . $rDVM . "</td></tr>";
$message .= "<tr><td colspan='2'> </td></tr>";
$message .= "<tr style='background: #eee'><td colspan='2'><strong>Reason for Referral & Expectations:</strong></td></tr>";
$message .= "<tr><td colspan='2'>" . $Reason_for_Referral . "</td></tr>";
$message .= "<tr><td colspan='2'> </td></tr>";
$message .= "<tr><td colspan='2'>Link to full history (available to UMN Staff Only): <a href='http://xxx/dermatology/form_view_rdvm.php?id=". $last_id ."' target='_blank'> http://xxx/dermatology/form_view_rdvm.php?id=". $last_id . "</a></td></tr>";
$message .= "<tr><td colspan='2'> </td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$message .= "<br />";
if(mail($to,$subject,$message,$headers)){
//redirect to the 'thank you' page
echo "<body><br /><br />
Thank you " .$rDVM ." for filling out the Dermatology form for " .$Pet_Name . " with, ". $ClientName . ". Your information has been received. Use the following link <a href=".$url." target='_blank'>" .$url . "</a> to submit photographs of your patients lesions or documents / test results
</body>";
} else {
echo 'Error!';
}
}
}
$stmt->close(); // close the prepared statement
$mysqli->close(); // close the database connection
?>
I would remove the square brackets on the field name. Probably you are receiving your data in the $_POST['LAB_Results[]'] variable.
As said #noid you must avoid duplicated ids.
Copied from the comments.
Please remove the last field, the text input named Lab_Results, the Other tests one. Probably you will have to deal with that field separately from the checkboxes.
Im trying to send an email to 2 variables currently I have tried to add 3 emails to an array and put that into a variable and get the other email from the form, I then dont know how to put both of those variables together when sending so they each have their own "to" but this does not work or something doesnt and I dont know what?? And yes I have real emails that I use these are placeholders for this!!!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['submit'])) {
$email = $_POST['LOGSE'];
$email2 = array("test#test.com", "test#test.com", "test#test.com");
$name = $_POST['full_name'];
$eventtitle = $_POST['EventT'];
$InCharge = $_POST['InCharge'];
$Venue = $_POST['Venue'];
$VenY = $_POST['VenR'];
if($VenY != "Yes"){
$ava = " Have not checked if";
}
else{
$ava = "";
}
$dates = $_POST['dateS'];
$datee = $_POST['dateE'];
$adults = $_POST['Adults'];
$children = $_POST['Children'];
$catreq = $_POST['CateReq'];
if (catreq != ''){
$catreq = $catreq;
}
else{
$catreq = "No Catering Needed";
}
$logreq = $_POST['LogReq'];
if (logreq != ''){
$logreq = $logreq;
}
else{
$logreq = "No Logistic Equipment Needed";
}
$itreq = $_POST['ITReq'];
if (itreq != ''){
$itreq = $itreq;
}
else{
$itreq = "No IT Needed";
}
$tran = $_POST['TransR'];
if($tran != Yes){
$tran = "NO ";
}
else{
$tran = "";
}
$Risk = $_POST['RiskR'];
if($Risk != Yes){
$Risk = "NO ";
}
else{
$Risk = "";
}
$othern = $_POST['OtherN'];
// The Email:
$from = 'test#test.com';
$to = $email;
$to = $email2;
$subject = 'Event Form ' .$eventtitle;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=UTF-8' . "\r\n";
$headers .= 'From: Event Form<test#test.com>' . "\r\n";
$headers .= 'Cc: test#test.com, test#test.com' . "\r\n";
$body = '<html>
<head>
<title>Event</title>
<style>
h1 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
h3 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
</style>
</head>
<body>
<h1>Event Details</h1>
<h3>Name: '.$name.'</h3>
<h3>Event Title: '.$eventtitle.'</h3>
<h3>Event Manager: '.$InCharge.'</h3>
<h3>Venue: '.$Venue.' - '.$ava.' Available</h3>
<h3>Date Start: '.$dates.'</h3>
<h3>Date End: '.$datee.'</h3>
<h3>Adults Attending: '.$adults.' Children Attending:
'.$children.'</h3>
<h3>Catering Requirements: '.$catreq.'</h3>
<h3>Logistic Requirements/Equipment: '.$logreq.'</h3>
<h3>IT Requirements: '.$itreq.'</h3>
<h3>Other Notes: '.$othern.'</h3>
<h3><font color="red">'.$tran.'</font>Transport Has Been
Booked</h3>
</body>
</html>' . "\r\n";
mail( $to, $subject, $body ,$headers );
/* echo "An Email Has Been Sent<br>Thank You."; */
header('Location: ./thanks.html');
}
}
The $to in mail function should be a string. If there are more than one email address then those should be comma separated. In your case you might need to do like following.
$to = $email . ','. implode(',', $email2);
Add email address with the comma
$email_to = "test#test.com,some#other.com,yet#another.net";
Also you can add
$headers = "Bcc: someone#domain.com";
Use a foreach on the array:
foreach($email2 as $to){
mail( $to, $subject, $body ,$headers );
}
Or like others are suggesting:
$to = $email.",".implode(",",$email2);
That doesn't make sense:
$to = $email;
$to = $email2;
Parmaeter $to should be a string of comma-seperated email-addresses, e.g.:
$to = $email1 . ", " . $email2 . ", " . $email3;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am adding some new validation to a current form, I have three separate arrays that I have built for select boxes and I need to be sure that the user is making at least one of the selections. At this point when the user fills our the form, it will submit and send, but the "Required" shows next to an empty select box in the form even through the notice says it has been sent and the form will send even if the user hasn't made a selection. I have tried searching everywhere for a solution, hoping to get a second set of eyes on this issue. Thank you in advance for your time!
The select box within the form -
<?php echo $monthMessage; ?>
<select name="mm" class="select-form-style">
<option>
- Select Month -
</option>
<?php
foreach ($months as $month) {
$selected = (!empty($mm) && $mm == $month) ? 'selected="selected"' : '';
?>
<option value="<?php echo $month;?>" <?php echo $selected;?>>
<?php echo $month;?>
</option>
<?php
}
?>
The PHP form validation
<?php #Registration
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December');
$season = array('Fall 2014', 'Winter 2014', 'Spring 2015', 'Summer 2015');
$locations = array('Priest River', 'Sandpoint', 'Online');
function makeSafe($value) {
return stripslashes(trim($value));
}
//if the form was subitted
if (!empty($_POST['submit'])) {
//form submitted through post, do validation
$authorization = (!empty($_POST['authorization'])) ? makeSafe($_POST['authorization']) : '';
$signature = (!empty($_POST['signature'])) ? makeSafe($_POST['signature']) : '';
$cc = makeSafe($_POST['cc']);
$ll = makeSafe($_POST['ll']);
$fname = makeSafe($_POST['fname']);
$mname = makeSafe($_POST['mname']);
$lname = makeSafe($_POST['lname']);
$mm = makeSafe($_POST['mm']);
$day = makeSafe($_POST['day']);
$year = makeSafe($_POST['year']);
$age = makeSafe($_POST['age']);
$school = makeSafe($_POST['school']);
$address = makeSafe($_POST['address']);
$city = makeSafe($_POST['city']);
$state = makeSafe($_POST['state']);
$zip = makeSafe($_POST['zip']);
$gender = makeSafe($_POST['gender']);
$email = makeSafe($_POST['email']);
$phone = makeSafe($_POST['phone']);
$altph = makeSafe($_POST['altph']);
$hp = makeSafe($_POST['hp']);
$packet = (!empty($_POST['signature'])) ? makeSafe($_POST['packet']) : '';
$message = '';
$problem = FALSE;
if(!empty($_POST['mm']))
{
$monthMessage .= '<p class="errorClass">Required</p>';
}
if(!empty($_POST['cc']))
{
$seasonMessage .= '<p class="errorClass">Required</p>';
}
if(!empty($_POST['ll']))
{
$locationMessage .= '<p class="errorClass">Required</p>';
}
if($_POST['authorizaton']!="1" AND $_POST['packet']!="1"){
$problem = TRUE;
$parentMessage .= '<p class="errorClass parentMsg">Please read and check the boxes below
</p>';
}
if($_POST['signature']!="1"){
$problem = TRUE;
$signatureMessage .= '<p class="errorClass">Required</p>';
}
//Check First Name
if (!eregi ('^[[:alpha:]\.\' \-]{2,}$',$fname)) {
$problem = TRUE;
$fnameMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[[:alpha:]\.\' \-]{2,}$',$lname)) {
$problem = TRUE;
$lnameMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[[:alnum:]\.\' \-]{4,}$', $school)) {
$problem = TRUE;
$schoolMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[[:alnum:]\.\' \#\-]{4,}$', $address)) {
$problem = TRUE;
$addyMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[[:alpha:]\.\' \-]{4,}$', $city)) {
$problem = TRUE;
$cityMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[[:alpha:]\.\' \-]{2,2}$', $state)) {
$problem = TRUE;
$stateMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[[:alnum:]][a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$',$email)) {
$problem = TRUE;
$emailMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[0-9]{5}(\-[0-9]{4})?$',$zip)) {
$problem = TRUE;
$zipMessage .= '<p class="errorClass">Required</p>';
}
if (!eregi ('^[0-9.\(\)\-\ ]{10,14}$', $phone)) {
$problem = TRUE;
$phoneMessage .= '<p class="errorClass">Required</p>';
}
if(!eregi('^[0-9]{2}$',$age)) {
$problem = TRUE;
$ageMessage .= '<p class="errorClass">Required</p>';
}
if(!eregi('^[0-9]{2,4}$',$year)) {
$problem = TRUE;
$yearMessage .= '<p class="errorClass">Required</p>';
}
if(!eregi('^[0-9]{1,2}$',$day)) {
$problem = TRUE;
$dayMessage .= '<p class="errorClass">Required</p>';
}
if ($problem == TRUE) {//Something went wrong
echo $message;
echo '';
}
else{
$to = "webangel119#yahoo.com";
$subject = "Buckle-Up New Student Registration";
$headers = 'From: jen.byron83#gmail.com' . "\r\n" .'X-Mailer: PHP/' . phpversion();
$msg .= "PLAIN TEXT EMAIL\n\n";
$msg .= "Location: $ll Class: $cc\n\n";
$msg .= "Name: $fname $mname $lname\n\n";
$msg .= "Birthday: $mm $day $year Age: $age Gender: $gender\n\n";
$msg .= "School: $school\n\n";
$msg .= "Address: $address\n\n";
$msg .= "City: $city State: $state Zip Code: $zip\n\n";
$msg .= "Phone: $phone Alternate Contact: $altph\n\n";
$msg .= "Email: $email\n\n";
if(mail($to, $subject, $msg, $headers) == false){
// Email failed
echo '<p>An error occured while trying to process your request</p>';
}
else {
echo '<p>Thank you for registering with Buckle-Up Driving School!</p>';
$authorization = '';
$ll = '';
$cc = '';
$fname = '';
$mname = '';
$lname = '';
$mm = '';
$day = '';
$year = '';
$age = '';
$school = '';
$address = '';
$city = '';
$state = '';
$zip = '';
$gender = '';
$email = '';
$phone = '';
$altph = '';
$hp = '';
$signature = '';
$packet = '';
}
}
}
?>
I'm not sure if i understood the problem, but if i follow my feeling about this, my answer will be :
Your mistake is up there :
if(!empty($_POST['mm']))
{
$monthMessage .= '<p class="errorClass">Required</p>';
}
So, if $_POST['mm'] is not empty, then "Required" will be shown. But you have a probleme, this value will never be empty :)
Even if no month is selected ("- Select Month -" selected), the navigator will send the content of the option tag as the value of select ;)
So you have $_POST['mm'] = "- Select Month -"
You have to do this test :
// if mm sent and is not empty
if(isset($_POST['mm']) && !empty($_POST['mm']))
{
// if mm is in $months array
if(in_array($_POST['mm'], $months))
{
// this value is not accepted or "- Select Month -" selected
}
else
{
// seems a month is selected and into your $months list
}
}
else
{
// this case happens if don't send "mm" in post
// or if the value of mm is empty
}
Btw, a value will never be sure by doing stripslashes(trim($val)); care with this.
Btw2, you can apply makeSafe() to your whole $_POST array by doing this :
foreach($_POST as $k => $v)
{
$P[$k] = makeSafe($v);
}
then call your data like $P['mm']
Hope it helped !
I am having a strange problem with this form. I have made it yesterday night and it was working fine, sending all the emails as it should. However, I've run it today and it won't simply work at all. I am always getting the error message. Any clues? Thank you.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$depart = $_POST['departamento'];
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$corpo = "Nova Mensagem\n";
$corpo .= "De: " . $name . "\n";
$corpo .= "Email: " . $email . "\n";
$corpo.=" Para o departamento " . $depart. "\n";
$corpo .= "Mensagem: " . $message . "\n";
if ($depart = administrativo)
{
$email_to = '';
}
elseif ($depart = financeiro)
{
$email_to = '';
}
elseif ($depart = Suporte)
{
$email_to = '';
}
else
{
$email_to = '';
}
$status = mail($email_to, $subject, $corpo, $headers);
if($status) {
echo "<script> window.location.href = ''; </script>";
}
else {
echo "<script> window.location.href = ''; </script>";
}
?>
Instead of = use == for comparison
for example - instead of:
if( $depart = administrativo)
use
if( $depart == "administrativo" )
You should enclose strings within quotes. Moreover, == (comparing objects of different types) && === (comparing objects of same types) are used for comparing and = is used for assigning. So, change the code as follows (inside the if statements) :
if ($depart == 'administrativo')
{
$email_to = '';
}
elseif ($depart == 'financeiro')
{
$email_to = '';
}
elseif ($depart == 'Suporte')
{
$email_to = '';
}
else
{
$email_to = '';
}