[英]Javascript pop-up box with e-mail submission
我目前已经建立了一个小问卷,最后,它弹出一个方框,上面写着“您完成了”。
我如何在其中包含一个额外的框,以便用户可以查看其答案,输入其电子邮件地址并单击提交,以便创建电子邮件并将其及其答案和详细联系信息发送给我上?
我会从网站上的其他位置复制一个简单的html表单,但是我认为我无法将html输入到外部.js脚本中,因此我呼吁专家寻求帮助。
以下代码段应该没有任何内容,但这可以帮助您。
survey.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 = 'name@domain.com';
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.