2017-02-04 4 views
0

Ich möchte ein Formular senden, die Kontrollkästchen haben, es funktionierte gut, aber ich nicht, was ich tat, dass ich jetzt einen Fehler jedes Mal, wenn ich es sendete. Ich denke, das Problem hat mit den Checkboxen zu tun, weil ich mich erinnere, dass ich in der Vergangenheit Probleme damit hatte. Ich arbeite mit einer einzigen Datei in PHP. Kann nicht Formular mit Kontrollkästchen senden PHP

Dies ist der Code für das Formular:

<div class="contactFrm"> 
<?php if(!empty($statusMsg)){ ?> 
      <p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p> 
     <?php } ?> 
     <form action="" method="post"> 
     <h6>Contact Information</h6> 
      <fieldset id="left"> 
      <h4>First Name</h4> 
      <input type="text" name="name" required> 
      <h4>Company Name</h4> 
      <input type="text" name="compname" required> 
      <h4>Phone Number</h4> 
      <input type="text" name="phone" required> 

      <h4>Date of Arrival</h4> 
      <input type="date" name="ardate" required> 
      </fieldset> 
      <fieldset id="right"> 
      <h4>Last Name</h4> 
      <input type="text" name="lname" required> 
      <h4>Website URL</h4> 
      <input type="text" name="website" required> 
      <h4>Email</h4> 
      <input type="email" name="email" required> 
      <h4>Date of Departure</h4> 
      <input type="date" name="depdate" required> 
      </fieldset> 
      <h4>What is your estimated time of arrival?</h4> 
      <input type="text" name="estimated_time" required> 
      <h4>How many groups will you be hosting?</h4> 
      <textarea name="groups" required> </textarea> 
      <h4>How many participants per group do you need to accommodate?</h4> 
      <input type="text" name="mparticipants" required> 
      <h4>What are the date/time scheduled for each group?</h4> 
      <textarea name="scheduled" required> </textarea> 
      <h4>What kind of set-up will you like?</h4> 
      <p>Additional fees may apply for living room/specialty set-ups.</p> 
      <p><div class="inline-field"> 
       <label> 
       <input type="checkbox" name="CheckboxGroup1[]" value="living_room" id="CheckboxGroup1_0"> 
       Living Room</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup1[]" value="conference_room" id="CheckboxGroup1_1"> 
       Conference Room</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup1[]" value="other" id="CheckboxGroup1_2"> 
       Other (please specify at the end of the form)</label> 
       <br> 
      </div></p> 
      <h6>Clients</h6> 
      <h4>How many individuals/clients from your company will be attending?</h4> 
      <p>These individuals will be stationed in the client room.</p> 
      <input type="text" name="attending"> 
      <h6>Services</h6> 
      <h4>Which technology services are you interested in?</h4> 
      <p>Check all that apply (All of these services are charged separately. Some will involve additional costs from the estimate provided to you.)</p> 
      <p><div class="inline-field"> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="sd_dvd" id="CheckboxGroup2_0"> 
       Stationary SD DVD Recording</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="hd_video" id="CheckboxGroup2_1"> 
       Stationary HD Video Recording</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="streaming" id="CheckboxGroup2_2"> 
       High Definition Video Streaming (Focus Vision (SD) streaming is also available)</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="smartboard" id="CheckboxGroup2_3"> 
       Smartboard (also functions as TV/DVD/PC)</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="translation" id="CheckboxGroup2_4"> 
       Translation Equipment</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="videographer" id="CheckboxGroup2_5"> 
       Videographer Assisted Recording (SD/HD)</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup2[]" value="other" id="CheckboxGroup2_6"> 
       Other (please specify on notes section)</label> 
       <br> 
      </div></p> 
      <h4>Will you need meal(s) to be provided?</h4> 
      <p>You will be able to pick from various menus once the booking is confirmed.</p> 
      <p><div class="inline-field"> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="participants" id="CheckboxGroup3_0"> 
       Yes, for Participants</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="clients" id="CheckboxGroup3_1"> 
       Yes, for Clients</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="breakfast" id="CheckboxGroup3_2"> 
       Breakfast</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="lunch" id="CheckboxGroup3_3"> 
       Lunch</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="dinner" id="CheckboxGroup3_4"> 
       Dinner</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="snacks" id="CheckboxGroup3_5"> 
       Snacks</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup3[]" value="beverages" id="CheckboxGroup3_6"> 
       Beverages</label> 
       <br> 
      </div></p> 
      <h4>Do you need research service(s)?</h4> 
      <p>Check all that apply.</p> 
      <p><div class="inline-field"> 
       <label> 
       <input type="checkbox" name="CheckboxGroup4[]" value="moderator" id="CheckboxGroup4_0"> 
       Moderator(s)</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup4[]" value="recruiting" id="CheckboxGroup4_1"> 
       Recruiting</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup4[]" value="reporting" id="CheckboxGroup4_2"> 
       Reporting and Analysis</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup4[]" value="quantitative" id="CheckboxGroup4_3"> 
       Quantitative</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup4[]" value="other" id="CheckboxGroup4_4"> 
       Other Research Services (please specify in the notes section)</label> 
       <br> 
       <label> 
       <input type="checkbox" name="CheckboxGroup4[]" value="na" id="CheckboxGroup4_5"> 
       N/A</label> 
       <br> 
      </div></p> 
      <h6>Additional Information</h6> 
      <h4>Please include any additional information or document that would help us facilitate your request.</h4> 
      <textarea name="additionalinfo"> </textarea> 
      <h4>Document Upload</h4> 
      <input type="file"> 
      <input type="submit" name="submit" value="Submit"> 
      <div class="clear"> </div> 
     </form> 

und dies ist die PHP:

<?php 
$statusMsg = ''; 
$msgClass = ''; 
if(isset($_POST['submit'])){ 
// Get the submitted form data 
$name = $_POST['name']; 
$lname = $_POST['lname']; 
$compname = $_POST['compname']; 
$phone = $_POST['phone']; 
$ardate = $_POST['ardate']; 
$website = $_POST['website']; 
$email = $_POST['email']; 
$depdate = $_POST['depdate']; 
$estimated_time = $_POST['estimated_time']; 
$groups = $_POST['groups']; 
$mparticipants = $_POST['mparticipants']; 
$scheduled = $_POST['scheduled']; 
$additionalinfo = $_POST['additionalinfo']; 
$attending = $_POST['attending']; 

$CheckboxGroup1 = (implode("," , $_POST['CheckboxGroup1'])); 


$CheckboxGroup2 = (implode("," , $_POST['CheckboxGroup2'])); 


$CheckboxGroup3 = (implode("," , $_POST['CheckboxGroup3'])); 


$CheckboxGroup4 = (implode("," , $_POST['CheckboxGroup4'])); 



// Check whether submitted data is not empty 
if(!empty($name) && !empty($lname) && !empty($compname) && !empty($phone) && !empty($ardate) && !empty($website) && !empty($email) && !empty($depdate) && !empty($estimated_time) && !empty($groups) && !empty($mparticipants) && !empty($scheduled) && isset($CheckboxGroup1) && isset($CheckboxGroup2) && isset($CheckboxGroup3) && isset($CheckboxGroup4) && !empty($attending) && !empty($additionalinfo)){ 

    if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){ 
     $statusMsg = 'Please enter your valid email.'; 
     $msgClass = 'errordiv'; 
    }else{ 
     // Recipient email 
     $toEmail = '[email protected]'; 
     $emailSubject = 'Facility Request Submitted by '.$name; 
     $htmlContent = '<h2>Facility Request Form</h2> 
      <h4>Name</h4><p>'.$name.'</p> 
      <h4>Last Name</h4><p>'.$lname.'</p> 
      <h4>Company Name</h4><p>'.$compname.'</p> 
      <h4>Phone Number</h4><p>'.$phone.'</p> 
      <h4>Date of Arrival</h4><p>'.$ardate.'</p> 
      <h4>Website URL</h4><p>'.$website.'</p> 
      <h4>Email</h4><p>'.$email.'</p> 
      <h4>Date of Departure</h4><p>'.$depdate.'</p> 
      <h4>What is your estimated time of arrival?</h4><p>'.$estimated_time.'</p> 
      <h4>How many groups will you be hosting?</h4><p>'.$groups.'</p> 
      <h4>How many participants per group do you need to accommodate?</h4><p>'.$mparticipants.'</p> 
      <h4>What are the date/time scheduled for each group?</h4><p>'.$scheduled.'</p> 
      <h4>What kind of set-up will you like?</h4><p>'.$CheckboxGroup1.'</p> 
      <h4>Which technology services are you interested in?</h4><p>'.$CheckboxGroup2.'</p> 
      <h4>How many individuals/clients from your company will be attending?</h4><p>'.$attending.'</p> 
      <h4>Will you need meal(s) to be provided?</h4><p>'.$CheckboxGroup3.'</p> 
      <h4>Do you need research service(s)?</h4><p>'.$CheckboxGroup4.'</p> 
      <h4>Additional Information</h4><p>'.$additionalinfo.'</p>'; 


     // Set content-type header for sending HTML email 
     $headers = "MIME-Version: 1.0" . "\r\n"; 
     $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

     // Additional headers 
     $headers .= 'From: '.$name.'<'.$email.'>'. "\r\n"; 


     // Send email 
     if(mail($toEmail,$emailSubject,$htmlContent,$headers)){ 
      $statusMsg = 'Your contact request has been submitted successfully !'; 
      $msgClass = 'succdiv'; 
     }else{ 
      $statusMsg = 'Your contact request submission failed, please try again.'; 
      $msgClass = 'errordiv'; 
     } 
    } 
}else{ 
    $statusMsg = 'Please fill all the fields.'; 
    $msgClass = 'errordiv'; 
} 
} 
?> 

Jede Hilfe meines Fehlers Hinweis darauf würde geschätzt.

+0

Erinnerung: Wenn checboxes nicht überprüft werden, werden sie nicht in $ _POST superglobal gesetzt – Andreas

+1

Auch bitte nächstes Mal zeigen Sie einfach genug Code, um das Problem zu bestimmen – mplungjan

+0

"Ich erhielt einen Fehler jedes Mal, wenn ich es sendete" - Welcher Fehler? – Quentin

Antwort

0

Ich habe Ihren Code überprüft und jedes Mal, wenn es funktioniert, aber Sie nicht damit umgehen, wenn Kontrollkästchen nicht ausgewählt, dass Zeit aufgetretenen Fehler einfach damit umgehen, möglicherweise Verwendung verpassen, es überprüft Kontrollkästchen Auswahl. andere weise welche Art von Fehler auftritt?

+0

Ich erhalte den Fehler: Die Übermittlung Ihrer Kontaktanfrage ist fehlgeschlagen. Bitte versuchen Sie es erneut. und ich erhalte keine E-Mail. – dileoh

1

Wenn Sie diese Meldung erhalten:

Your contact request submission failed, please try again.

Dann ist dieser Teil des Codes wirft diese Nachricht:

// Send email 
     if(mail($toEmail,$emailSubject,$htmlContent,$headers)){ 
      $statusMsg = 'Your contact request has been submitted successfully !'; 
      $msgClass = 'succdiv'; 
     }else{ 
      $statusMsg = 'Your contact request submission failed, please try again.'; 
      $msgClass = 'errordiv'; 
     } 

was bedeutet, dass die E-Mail() Funktion false zurückkehrt. Stellen Sie sicher, dass die Funktion mail() funktioniert, indem Sie Parameter übergeben, von denen Sie wissen, dass sie gültig sind, z. B. diejenigen aus dem anderen Kontaktformular, von dem Sie sagen, dass es funktioniert. Versuchen Sie vielleicht auch, die $ Header zu entfernen und sehen Sie, ob das hilft, da dieser Teil optional ist.