PHP表单提交但不显示1个值

时间:2014-11-01 20:17:41

标签: php forms

我有一个PHP表单,除了1件事以外,我很疯狂,试图弄清楚如何使它工作。它通过电子邮件向我发送结果,除了“Plus1”字段始终为空白外,所有内容都显示在电子邮件中。如何在提交的电子邮件表单中显示值?谢谢你的帮助。

您可以在http://michyandsmiley.com上看到它。

以下是表单的代码:

<div id="rsvp" class="text-center" data-scroll-reveal>
            <div class="heading">
                <h2>RSVP</h2>
                <p><span></span><i class="fa fa-heart"></i><span></span></p>
            </div>
            <form role="form" name="contactform" action="process.php">
                <div class="row">
                    <div id="name-group" class="form-group col-xs-12">
                        <label for="inputName">Your Name</label>
                        <input type="text" class="form-control" id="inputName" name="inputName" placeholder="John Doe">
                    </div>
                </div>
                <div class="row">
                    <div id="email-group" class="form-group col-xs-12">
                        <label for="inputEmail">Your Email</label>
                        <input type="email" class="form-control" id="inputEmail" name="inputEmail" placeholder="name@domain.com">
                    </div>
                </div>
                <div class="row">
                    <div id="guests-group" class="form-group col-xs-6">
                        <label for="selectGuests">Total Guests</label>
                        <select class="form-control" name="selectGuests" id="selectGuests">
                            <option value="1" selected>1</option>
                            <option value="2">2</option>
                        </select>
                    </div>
                    <div id="plusone-group" class="form-group col-xs-6">
                        <label for="inputPlus1">Guest's Name</label>
                        <input type="Plus1" class="form-control" id="inputPlus1" name="inputPlus1" placeholder="Jane Doe">
                    </div>
                    <div class="row">
                    <div id="attending-group" class="form-group col-xs-12">
                        <label for="selectAttending">I am...</label>
                        <select class="form-control" name="selectAttending" id="selectAttending">
                            <option value="Attending" selected>So excited to attend! Yay!</option>
                            <option value="Not Attending">Sorry to miss it. Boo!</option>
                        </select>
                    </div>
                </div>
                <div class="row">
                    <button type="submit" class="btn btn-lg">Submit Your RSVP!</button>
                </div>
            </form>
        </div>

对于“process.php”代码:

<?php

$send_to = '(removed my email for privacy purposes)';

$errors         = array();      // array to hold validation errors
$data           = array();      // array to pass back data

 // validate the variables ======================================================
// if any of these variables don't exist, add an error to our $errors array

if (empty($_POST['inputName']))
    $errors['name'] = 'Name is required.';

if (empty($_POST['inputEmail']))
    $errors['email'] = 'Email is required.';

// return a response ===========================================================

// if there are any errors in our errors array, return a success boolean of false
if ( ! empty($errors)) {

    // if there are items in our errors array, return those errors
    $data['success'] = false;
    $data['errors']  = $errors;
} else {

    // if there are no errors process our form, then return a message

    //If there is no errors, send the email
    if( empty($errors) ) {

        $subject = 'Wedding RSVP Form';
        $headers = 'From: ' . $send_to . "\r\n" .
            'Reply-To: ' . $send_to . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

        $message = 'Name: ' . $_POST['inputName'] . '

Email: ' . $_POST['inputEmail'] . '

Guests: ' . $_POST['selectGuests'] . '

GuestName: ' . $_POST['inputPlus1'] . '

Attending: ' . $_POST['selectAttending'];

        $headers = 'From: RSVP Form' . '<' . $send_to . '>' . "\r\n" . 'Reply-To: ' .     $_POST['inputEmail'];

        mail($send_to, $subject, $message, $headers);

    }

    // show a message of success and provide a true success variable
    $data['success'] = true;
    $data['message'] = 'Thank you!';
}

// return all our data to an AJAX call
echo json_encode($data);

1 个答案:

答案 0 :(得分:0)

您没有字段列表中的字段发布到服务器:

var formData = {
'inputName'             : $('input[name=inputName]').val(),
'inputEmail'            : $('input[name=inputEmail]').val(),
'selectGuests'          : $('select[name=selectGuests]').val(),
'selectAttending'       : $('select[name=selectAttending]').val()
};