我的新手在這裏閃閃發光......我設法拼湊出一個效果很好的表單郵件工具,但現在我需要添加兩個字段,並且我對如何添加去做吧。幾個月來,我已經評論了一些我不需要的東西,但現在我被卡住了。拼湊一個jQuery表單郵件
我從本教程借使原有的形式: http://trevordavis.net/blog/tutorial/ajax-forms-with-jquery/
但後來我拆解它使一個通訊的電子郵件註冊表單,所以我需要的字段有:
收件人電子郵件(我的電子郵件,硬編碼)
發件人的電子郵件地址
- 的S ubject(硬編碼)
- 名字和城市的 體內的消息
對於我的形式,我有這樣的:
<div>
<?php include('verify.php'); ?>
<form action="index_success.php" method="post" id="sendEmail" class="email">
<h3 class="register2">Newsletter Signup:</h3>
<ul class="forms email">
<li class="name"><label for="yourName">Name: </label>
<input type="text" name="yourName" class="info" id="yourName" value=" " /><br>
</li>
<li class="city"><label for="yourCity">City: </label>
<input type="text" name="yourCity" class="info" id="yourCity" value=" " /><br>
</li>
<li class="email"><label for="emailFrom">Email: </label>
<input type="text" name="emailFrom" class="info" id="emailFrom" value="<?= $_POST['emailFrom']; ?>" />
<?php if(isset($emailFromError)) echo '<span class="error">'.$emailFromError.'</span>';
?>
</li>
<li class="buttons email">
<button type="submit" id="submit">Send</button>
<input type="hidden" name="submitted" id="submitted" value="true" />
</li>
</ul>
</form>
</div>
emailcontact.js:
$(document).ready(function(){
$("#submit").click(function(){
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;
var emailFromVal = $("#emailFrom").val();
if(emailFromVal == '') {
$("#emailFrom").after('<span class="error">You forgot to enter the email address to send from.</span>');
hasError = true;
} else if(!emailReg.test(emailFromVal)) {
$("#emailFrom").after('<span class="error">Enter a valid email address to send from.</span>');
hasError = true;
}
var subjectVal = $("#subject").val();
if(subjectVal == '') {
$("#subject").after('<span class="error">You forgot to enter your name.</span>');
hasError = true;
}
var messageVal = $("#message").val();
if(messageVal == '') {
$("#message").after('<span class="error">You forgot to enter your city.</span>');
hasError = true;
}
if(hasError == false) {
$(this).hide();
$("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
$.post("/includes/sendemail.php",
//emailTo: emailToVal,
{ emailFrom: emailFromVal, subject: subjectVal, message: messageVal },
function(data){
$("#sendEmail").slideUp("normal", function() {
$("#sendEmail").before('<h3 class="register2">Success!</h3><p class="emailbox">You are on the Newsletter email list.</p>');
});
}
);
}
return false;
});
});
sendmail.php:
<?php
$mailTo = $_POST['emailTo'];
$mailFrom = $_POST['emailFrom'];
$subject = $_POST['yourName'];
$message = $_POST['yourCity'];
mail('[email protected]','Newsletter', 'Name='.$subject. ' City='.$message, "From: ".$mailFrom);
?>
感謝您的幫助!我正在試圖找出這個問題。
你對你的假設是正確的 - 我的換行符沒有翻譯正確 - 我編輯了我的帖子。感謝您對此的回覆...... – Joel 2010-05-05 19:10:32
好的。得到它的工作。還有一些額外的部分,但你的幫助讓我朝着正確的方向前進! – Joel 2010-05-05 19:47:51