PHP复选框表单

时间:2015-05-19 08:53:55

标签: php html forms email

我正在尝试将复选框的输出发布到电子邮件中但是我遇到了真正的困难? 任何人都有任何想法:

$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" <example@gmail.com>';
$to = '<example@gmail.com>,<example@gmail.com>';
$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
);

我的HTML表单是:

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

我真的不知道为什么这不起作用,因为我只是使用IF语句来确定它? 请帮忙!

1 个答案:

答案 0 :(得分:2)

将您的代码更新为。

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";
}