简体   繁体   English

将表单提交到电子邮件,然后重定向到新页面(不使用php)

[英]Submit form to email, then redirect to new page (without php)

The client has a section of her site that is not navigable through any other pages. 客户在其网站的一部分中无法浏览任何其他页面。 To get to these pages she wants the user to fill out this form. 为了进入这些页面,她希望用户填写此表单。 It's a non-for-profit, so she basically just wants to see how many people are getting to these pages that have a product available for free so she can report on that. 这是一个非营利性组织,所以她基本上只是想看看有多少人正在访问这些页面,这些页面都有免费提供的产品,因此她可以进行举报。 So there is a page with a form. 因此,存在一个带有表单的页面。 She wants the user to submit the form and then be re-directed to another page. 她希望用户提交表单,然后将其重定向到另一个页面。 Normally I would do this really easily with PHP but unfortunately she hosts the site through some local fools and they don't support PHP 通常,我会使用PHP真正轻松地做到这一点,但是不幸的是,她通过一些本地傻瓜托管了该网站,而且他们不支持PHP

So the question is, how do I get this form to submit to her email, then redirect to a different page (videos.html) from the current page with the form (video-form.html)? 因此,问题是,如何获取此表单以提交给她的电子邮件,然后使用表单(video-form.html)从当前页面重定向到其他页面(videos.html)?

I have this form: 我有这个表格:

        <form id="myForm" action="mailto:mail@mail.net" method="post" name="VideoFormAction">
            <table cellspacing="1" cellpadding="1" width="46%">
                <tr>
                    <td valign="top" class="shade1"><font color="red"><b>*</b></font> Email Address</td>
                    <td valign="top"><input type="text" name="Mail" value="" size="30"></td>
                </tr>

                <tr>
                    <td valign="top" class="shade2">Name</td>
                    <td valign="top"><input value="" name="Name" type="text" size="30" maxlength="100"></td>
                </tr>

                <tr>
                    <td valign="top" align="center">
                        <font color="red"><b>*</b></font> = required field
                    </td>
                    <td valign="top">
                        <button class="button">Submit</button>
                    </td>
                </tr>
            </table>
         </form>

I have tried some javascript: 我尝试了一些JavaScript:

<script>
document.getElementById("myForm").onsubmit = function() {
    setTimeout(function(){
        window.location.href = "http://www.funducate.net/videos.html";  
    }, 1);
};
</script>

Which for whatever reason will not work. 无论出于何种原因都不起作用。 I have found multiple suggestions through search to try many different variations of the above, all of which failed. 我通过搜索找到了多个建议,以尝试上述方法的许多不同变体,但所有尝试都失败了。 The last ditch effort was even putting a timeout into it as you see above. 正如您在上面看到的那样,最后的沟渠工作甚至是超时。 I imagine it doesn't work because the submit button performs the action="" and then doesn't continue. 我想这是行不通的,因为“提交”按钮执行action =“”,然后不再继续。

Are there any other alternatives? 还有其他选择吗? Remember, I can't use PHP (i know it's ridiculous but it's what I got) 记住,我不能使用PHP(我知道这很荒谬,但这就是我得到的)

You could read the form values via either jQuery or javascript, save them to variables, construct a message body and email the form contents. 您可以通过jQuery或javascript读取表单值,将它们保存为变量,构造消息正文并通过电子邮件发送表单内容。

See below for more information: 请参阅下面的详细信息:

How to send an email from JavaScript 如何从JavaScript发送电子邮件

More information on Mandrill 有关Mandrill的更多信息

After sending the email, redirect the page as you have done (correctly) in your code -- but without the setTimeout. 发送电子邮件后,按照代码中的操作(正确)重定向页面-但不设置setTimeout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM