Jquery PHP表单提交-如何获取要显示的表单输入?

Jquery PHP表单提交-如何获取要显示的表单输入?,php,jquery,forms,submit,Php,Jquery,Forms,Submit,我有一个联系方式>www.bgv.co.za/testspace/contact_3.php 它使用jquery验证和PHP。我有一些添加/删除类位来隐藏或显示感谢的标题,还有一些php if设置来回显成功的表单提交输入 我的问题是,在提交时,您会看到感谢页面,但div>sadhu没有显示用户输入的数据。。。事实上,它没有显示为div-请帮助 以下是我的Jquery: $(document).ready(function(){ $('#contactform').validate({ showE

我有一个联系方式>www.bgv.co.za/testspace/contact_3.php 它使用jquery验证和PHP。我有一些添加/删除类位来隐藏或显示感谢的标题,还有一些php if设置来回显成功的表单提交输入

我的问题是,在提交时,您会看到感谢页面,但div>sadhu没有显示用户输入的数据。。。事实上,它没有显示为div-请帮助

以下是我的Jquery:

$(document).ready(function(){
$('#contactform').validate({
showErrors: function(errorMap, errorList) {
   //restore the normal look
   $('#contactform div.xrequired').removeClass('xrequired').addClass('_required');
   //stop if everything is ok
   if (errorList.length == 0) return;
   //Iterate over the errors
   for(var i = 0;i < errorList.length; i++)
   $(errorList[i].element).parent().removeClass('_required').addClass('xrequired');
},
submitHandler: function(form) {             
    $('h1.success_').removeClass('success_').addClass('success_form');
    $("#content").empty();
    $("#content").append('#sadhu');
    $('#contactform').hide();
    var usr = document.getElementById('contactname').value;
    var eml = document.getElementById('email').value;
    var msg = document.getElementById('message').value;
    document.getElementById('out').innerHTML = usr + " " + eml + msg;
    document.getElementById('out').style.display = "block";
    form.submit();
}
});
});
以下是我的PHP:

$subject = "Website Contact Form Enquiry";

//If the form is submitted
if(isset($_POST['submit'])) {

//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
    $hasError = true;
} else {
    $name = trim($_POST['contactname']);
}

//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '')  {
    $hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
    $hasError = true;
} else {
    $email = trim($_POST['email']);
}

//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
    $hasError = true;
} else {
    if(function_exists('stripslashes')) {
        $comments = stripslashes(trim($_POST['message']));
    } else {
        $comments = trim($_POST['message']);
    }
}

//If there is no error, send the email
if(!isset($hasError)) {
    $emailTo = 'info@bgv.co.za'; //Put your own email address here
    $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments";
    $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

    mail($emailTo, $subject, $body, $headers);
    $emailSent = true;

}
}
这是我的表格:

            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform" >
        <div class="_required"><p class="label_left">Name*</p><input type="text" size="50" name="contactname" id="contactname" value="" class="required" /></div><br/><br/>
        <div class="_required"><p class="label_left">E-mail address*</p><input type="text" size="50" name="email" id="email" value="" class="required email" /></div><br/><br/>
        <p class="label_left">Message</p><textarea rows="5" cols="50" name="message" id="message" class="required"></textarea><br/>
        <input type="submit" value="submit" name="submit" id="submit" />
        </form>
没有在任何地方定义。您正在使用Javascript代码将其附加到内容中,但它并不存在

$("#content").append('#sadhu');
你可能想要像这样的东西

$("#content").append("<div id='sadhu'>stuff in here...</div>");

好的,谢谢你,迈克尔。。。。但这里的东西之间的东西应该是什么输入的形式,由用户。我应该怎么做呢?现在我把它作为php echo变量。
document.getElementById('out').innerHTML = usr + " " + eml + msg;
document.getElementById('out').style.display = "block";
$("#content").append("<div id='sadhu'>" + $("#out").html() + "</div>");