我目前已经设置了一个小问卷,最后,当前弹出一个只是说“你完成了”的方框。
如何让它包含一个左右的附加框,以便用户可以查看他们的答案,输入他们的电子邮件地址并单击提交,以便创建电子邮件并将其发送给我和联系方式?
我会从我网站上的其他地方复制一个简单的html表单,但我相信我无法将html输入到外部.js脚本中,所以我请专家寻求帮助。
下面的编码应该没有任何内容,但这可以帮助你帮助我。
问卷调查.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>
答案 0 :(得分:0)
如果您希望他们能够从弹出窗口更改答案,则无法通过警报执行此操作。如果您只想向他们展示他们的答案,并且有一个电子邮件地址框,则可能会这样做。
如果您只想用一个框来显示他们的答案以输入电子邮件地址,您可以尝试prompt pop-up。
如果您希望他们能够从弹出框中更改答案,您可能需要自己创建答案。类似于these。