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


Javascript pop-up box with e-mail submission

我目前已经建立了一个小问卷,在最后,它会弹出一个框,上面只写着"你完成了"。

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

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

如果你想让他们能够从弹出窗口中更改答案,那么你不能通过警报来做到这一点。如果你只想向他们展示他们的答案,并在一个盒子里放一个电子邮件地址,这是可能的。

如果你只想用一个输入电子邮件地址的框来显示他们的答案,你可以尝试弹出提示。

如果你想让他们能够从弹出框中更改答案,你可能必须自己创建。像这样的东西。