2
我目前已經設置了一個小問卷,最終當前彈出一個只是說'已完成'的框。使用電子郵件提交Javascript彈出框
如何讓這個包含一個額外的框,以便用戶可以查看他們的答案,輸入他們的電子郵件地址並點擊提交,這樣就可以創建一個電子郵件併發送給我答案和詳細聯繫方式?
我會從我的網站上的其他地方複製一個簡單的html表單,但我相信我不能將html輸入到外部.js腳本中,所以我請求專家幫忙。
下面的代碼應該沒有什麼問題,但這可能會幫助你。
的questionnaire.js:
function QuestionnaireViewModel() {
var self = this;
var currentQuestionIndex = 0;
var questions = [
{
caption: 'Q1?',
answers: [
{ caption: 'Q1A1' },
{ caption: 'Q1A2' }
]
},
{
caption: 'Q2',
answers: [
{ caption: 'Q2A1' },
{ caption: 'Q2A2' }
]
},
{
caption: 'Q3',
answers: [
{ caption: 'Q3A1' },
{ caption: 'Q3A2' }
]
},
{
caption: 'Q4',
answers: [
{ caption: 'Q4A1' },
{ caption: 'Q4A2' }
]
}
];
self.currentQuestion = new ko.observable(questions[0]);
self.progress = new ko.observableArray();
self.selectQuestion = function (answer) {
self.progress.push({
question: questions[currentQuestionIndex].caption,
answer: answer.caption
});
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
self.currentQuestion(questions[currentQuestionIndex]);
} else {
alert('Your done');
}
};
};
$(document).ready(function() {
ko.applyBindings(new QuestionnaireViewModel());
});
形式handler.php:
<?php
$errors = '';
$myemail = '[email protected]';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if(empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. "
. " Here are the details:\n Name: $name \n "
. "Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: thankyou.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
謝謝你的迴應,傑夫。我不需要在彈出窗口中可以操作的答案。我現在看到如何創建一個用戶可以輸入他們的電子郵件的框。也許我在PHP和JavaScript之間有點暈,所以請原諒我,但是我怎樣才能收集變量(答案)以顯示給調查問卷,然後將答案和電子郵件發送給發送到我的電子郵件地址? – sn0wy 2013-02-25 16:31:02
就像這樣:http://jsfiddle.net/jeffshaver/5q5Dj/將工作...而實際上,你需要使用彈出提示框。我錯過了。我正在改變我的答案來反映這一點。 – 2013-02-25 16:56:43