0

I'm trying to post the output of a checkbox to email however I'm having real difficulty? Anyone any idea:

$inputName = $_POST["inputName"];
$inputDate = $_POST["inputDate"];
$inputStart = $_POST["inputStart"];
$inputEnd = $_POST["inputEnd"];
$inputFacilities = $_POST["inputFacilities"];
//$inputAssistanceDuration = $_POST["inputAssistanceDuration"];
$inputComment = $_POST["inputComment"];

if (isset($_POST['inputAssistanceSetup'])) {
    // Checkbox is selected
    $inputAssistanceSetup = ["Yes"];
} else {
    // Alternate code
    $inputAssistanceSetup = ["No"];
}


if ( empty($_POST['inputAssistanceDuration']) ) {
    // Checkbox is selected
    $inputAssistanceDuration = ["No"];
} else {
    // Alternate code
    $inputAssistanceDuration = ["Yes"];
}




require_once "Mail.php";
$from = '"IT Request" <[email protected]>';
$to = '<[email protected]>,<[email protected]>';
$subject = "IT Facilities Request: {$inputName}";
$body = "Name: {$inputName}\nDate: {$inputDate}\nFrom: {$inputStart}\nUntil: {$inputEnd}\nFacilities: {$inputFacilities}\nAssistance for Setup: {$inputAssistanceSetup}\nAssistance for Duration: {$inputAssistanceDuration}\nComment: {$inputComment}";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

My HTML form is:

                    <!--IT Support Assistance-->
                    <div class="form-group">
                      <label for="inputAssistance" class="col-lg-2 control-label">Assistance</label>
                        <div class="col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input name="inputAssistanceSetup" value="Setup" type="checkbox"> For Setup
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input name="inputAssistanceDuration" value="Duration" type="checkbox"> For Duration
                                </label>
                            </div>
                        </div>
                    </div>

I really have no idea as to why this isn't working, as I'm simply using an IF statement to determine it? Please help!

2
  • You should check its existence using isset($_POST['inputAssistanceSetup']) Commented May 19, 2015 at 8:55
  • Why are you wrapping your $inputAssistanceSetup = ["Yes"]; assigned value in brackets? Commented May 19, 2015 at 8:55

1 Answer 1

2

Update your code to.

if (isset($_POST['inputAssistanceSetup'])) {
    // Checkbox is selected
    $inputAssistanceSetup = "Yes";
} else {
    // Alternate code
    $inputAssistanceSetup = "No";
}

if ( isset($_POST['inputAssistanceDuration']) ) {
    // Checkbox is selected
    $inputAssistanceDuration = "Yes";
} else {
    // Alternate code
    $inputAssistanceDuration = "No";
}
Sign up to request clarification or add additional context in comments.

8 Comments

Hm, this seems to be getting there. The email output now displays 'NO' regardless of the box being checked now?
@GlenRitchie what do you mean by email output now displays 'NO'
The output shows the following: Facilities: test (break) Assistance for Setup: No (break) Assistance for Duration: No (break) Comment: none Even if the box is checked...
Try this echo $_POST["inputComment"]; and see if you get comment.
Sorry, that was my bad choice of input the 'comment' text field works fine, the check boxes return the output 'No' regardless of their status.
|

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.