0

I want to send a form that have checkboxes in it, it was working fine but I do not what I did that now I received an error everytime I send it. I think the problem has to do with the checkboxes because I recall that I had problems with them in the past. I am working with a single file in PHP.

This is the code for the form:

<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>

and this is the 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';
}
}
?>

Any help pointing out my error would be appreciated.

11
  • Reminder: If checboxes are not checked they will not be set in the $_POST superglobal Commented Feb 4, 2017 at 17:23
  • 1
    Also please next time just show enough code to determine the issue Commented Feb 4, 2017 at 17:23
  • "I received an error everytime I send it" — What error? Commented Feb 4, 2017 at 17:24
  • 1
    Please provide a minimal reproducible example, emphasis on the minimal. Commented Feb 4, 2017 at 17:24
  • Using valid HTML wouldn't hurt (and your heading ordering is very strange too). Commented Feb 4, 2017 at 17:25

2 Answers 2

1

If you are getting this message:

Your contact request submission failed, please try again.

Then this portion of the code is throwing that message:

// 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';
        }

Which means that the mail() function is returning false. Make sure that the mail() function works by passing in parameters you know are valid, such as those from the other contact form you say is working. Also, maybe try removing the $headers and see if that helps, since that part is optional.

Sign up to request clarification or add additional context in comments.

Comments

0

i have checked your code and every time it's working but you don't handle it if checked box not selected that time occurring error just handle it, may be use miss it checked boxed selection . other wise what type of error occurring ?

1 Comment

I get the error: Your contact request submission failed, please try again. and I don't receive any email.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.