gpt4 book ai didi

php - 带有电子邮件提交的Javascript弹出框

转载 作者:行者123 更新时间:2023-11-28 03:34:53 25 4
gpt4 key购买 nike

我目前已经设置了一个小调查问卷,最后会弹出一个框,上面写着“你完成了”。

我如何让它包含一个额外的框,以便用户可以查看他们的答案,输入他们的电子邮件地址并单击提交,以便创建一封电子邮件并将他们的答案发送给我和详细联系方式?

我会从我网站的其他地方复制一个简单的 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>

最佳答案

如果您希望他们能够从弹出窗口更改他们的答案,那么您不能通过警报来完成此操作。如果您只是想向他们展示他们的答案,并且有一个用于电子邮件地址的框,则可以这样做。

如果你只想用一个框来显示他们的答案来输入一个电子邮件地址,你可以试试 prompt pop-up .

如果您希望他们能够从弹出框中更改答案,您可能必须自己创建。类似于 these .

关于php - 带有电子邮件提交的Javascript弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15070912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com