如何修复jQuery / PHP表单提交?

时间:2013-11-06 01:27:57

标签: php jquery forms

我正在更新客户端网站,现在已经破坏了以前工作的简单联系表单。当我收到返回的错误消息时,似乎HTML表单从jQuery文件发送和接收数据,尽管它没有将数据传递到PHP文件以发送电子邮件。如果我将数据直接从HTML表单发送到PHP文件,则会发送一封电子邮件。错误可能是在jQuery的最后,虽然我的搜索如何解决没有透露答案。关于如何使这项工作的任何想法?

HTML表单

<form id="rsForm" action="#" onsubmit="return goContact(this);" name="rsForm">
<input id="formNam" type="hidden" name="formNam" value="3" />
<div class="CU_row">
<div class="CU_form_title"><label for="firstName">First Name:</label></div>
<div class="CU_form_entry"><input id="firstName" maxlength="120" size="39" name="first" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="lastName">Last Name:</label></div>
<div class="CU_form_entry"><input id="lastName" maxlength="120" size="39" name="last" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="emailAddress">Email:</label></div>
<div class="CU_form_entry"><input id="emailAddress" maxlength="120" size="39" name="email" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="subjectLine">Subject:</label></div>
<div class="CU_form_entry"><input id="subjectLine" maxlength="120" size="39" name="subject" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="messageCopy">Message:</label></div>
<div class="CU_form_entry"><textarea id="messageCopy" rows="6" cols="30" name="message"></textarea> <span class="redT">*</span></div>
</div>
<div id="CU_reset"><input type="reset" value="Reset" /></div>
<div id="CU_submit"><input type="submit" name="Submit" value="Submit" /></div>

jQuery文件

// JavaScript Document

function goContact(theForm){
//Validate the forms and create the array to send.
var frmName = theForm.formNam.value;


//Validate Common elements.
if(theForm.firstName.value.length < 1){
    alert("You must supply a First Name");
    theForm.firstName.focus();
    return false;
}
if(theForm.lastName.value.length < 1){
    alert("You must supply a Last Name");
    theForm.lastName.focus();
    return false;
}
if(theForm.email.value.length < 1){
    alert("You must supply an Email");
    theForm.email.focus();
    return false;
}
if(theForm.subjectLine.value.length < 1){
    alert("You must supply a Subject");
    theForm.subjectLine.focus();
    return false;
}
if(theForm.messageCopy.value.length < 1){
    alert("You must supply a Message");
    theForm.messageCopy.focus();
    return false;
}

sendAjaxReq($(theForm).serialize(true));

return false;   
}

function showResult(messageText){
//Show the pop up with the confirmation.
$('msgWindow').innerHTML = messageText;
$('rsForm').reset();
$('frmInter').hide();
}

function sendAjaxReq(formEms){
//Send he ajax request
 var rSp = new Ajax.Request("includes/sendContact.php", {
        method: 'get',
        parameters: formEms,
        onComplete: receiveRespon});

}

function receiveRespon(oReq, JSONRsp){
//Receive the response from the ajax request.\
var result = JSONRsp;

if(result){
    showResult(result);
}
}

PHP文件

<?php 


if(isset($_GET['Submit'])){
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: no-reply@sitename.com' . "\r\n";
'X-Mailer: PHP/' . phpversion();

$to = "info@sitename.com";
$subject = "Inquiry from " . $_SERVER['HTTP_HOST'];
$message = "A client has sent a contact us email\n\n";

foreach($_GET AS $field => $value) {
    $message .= "field = $field, value = $value \n\n";
}

$mailSent = mail($to, $subject, $message, $headers);

    $arr = "Your message has been received.";
    header('X-JSON: ('.json_encode($arr).')'); 

}

?>

0 个答案:

没有答案