简体   繁体   English

HTML表单提交到数据库并重定向到“谢谢”页面

[英]HTML form Submission to Database and redirect to Thank you page

A simple popup HTML form when submits need to do two actions. 提交时,一个简单的弹出HTML表单需要执行两个操作。 1. Send customer information to the existing database 2. Redirect customer to Thank you page. 1.将客户信息发送到现有数据库。2.将客户重定向到“谢谢”页面。

With the help of another Stackoverflow member were able to work on this code. 在另一个Stackoverflow成员的帮助下,他们可以处理此代码。 But,the code is not working. 但是,代码不起作用。 I feel that I am doing something terribly wrong to the code, sorry unable to figure it out. 我觉得我对代码做了非常糟糕的事情,对不起无法弄清楚。 Please help! 请帮忙!

Currently, the form is getting sent to database, but redirects to the existing Mailing list signup page, if I change the action to thank you page, then the form is sent to thank you page, but no submission to database. 当前,该表单已发送到数据库,但是重定向到现有的邮件列表注册页面,如果我将操作更改为“谢谢”页面,则该表单将发送给“谢谢”页面,但没有提交到数据库。

I prefer to use Jquery, I am not much familiar with PHP, if someone can guide me, I can implement PHP as well. 我更喜欢使用Jquery,我对PHP不太熟悉,如果有人可以指导我,我也可以实现PHP。 The form is getting redirected even if nothing entered in the Email Adress Input. 即使在“电子邮件地址”输入中未输入任何内容,该表单也将被重定向。 Is there a way to tell the customer to enter valid email address and then to take him to Thankyou page? 有没有办法告诉客户输入有效的电子邮件地址,然后带他到Thankyou页面? Thanks 谢谢

Database address:" http://www.mywebsite.com/MailingList_subscribe.asp " Thank you page address: " https://www.mywebsite.com/Articles.asp?ID=252 " 数据库地址:“ http://www.mywebsite.com/MailingList_subscribe.asp ”谢谢页面地址:“ https://www.mywebsite.com/Articles.asp?ID=252

HTML Header HTML标题

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">

$(document).ready(function(){
    $('#formId').submit(function(){
        $.ajax({
            type: "POST",
            url: "http://www.mywebsite.com/MailingList_subscribe.asp",
            context: document.body
        }).success(function() {
            location.href = "https://www.mywebsite.com/Articles.asp?ID=252";
        });
    });
  )};
</script>

HTML BODY: HTML正文:

 <form name="MailingList" id="formId" method="post" action="http://www.mywebsite.com/MailingList_subscribe.asp">  
        <input type="text" name="emailaddress" placeholder="Email Address" maxlength="100" size="28"> <br>
        <input type="submit" name="Submit"  value="Submit" width="260px">
      </form>

CSS: CSS:

input[type=text] {

padding:1px; border:1px solid #c6c7cc;
box-shadow: inset 0 1px 1px
-webkit-border-radius: 13px;
width: 98%;
font-size:14px;
font-family: Lucida Grande;
font-weight: regular;
margin-left: 2px;
margin-top:10px;

}

input[type=submit] {

background: #9B1C1F;
width: 100%;
font-family: Lucida Grande;
color: #ffffff;
font-weight: bold;
font-size:18px;
text-align:left;
margin-top:10px;
padding:5px 15px;
margin-left:0px;
border:0 none;
cursor:pointer;
display: inline-block;

}
$(document).ready(function(){
    $('#formId').submit(function(){
        $.ajax({
            type: "POST",
            url: "http://www.my website.com/MailingList_subscribe.asp",
            context: document.body
        }).success(function() {
            location.replace("https://www.teabeyond.com/Articles.asp?ID=252"); //<=== edit
        });
    });
  )};

And to force the user to enter valid email you can use 并强迫用户输入有效的电子邮件,您可以使用

<input type=email />  

instead of 代替

<input type=text />

Use input type="email" Easiest Email Validation but only works in modern browsers http://www.w3schools.com/html/html5_form_input_types.asp 使用输入type =“ email”最简单的电子邮件验证,但仅在现代浏览器中有效http://www.w3schools.com/html/html5_form_input_types.asp

I would recommend using email validation in PHP (on server side) for security reasons , because by-passing client side is very easy (one example is famous cURL library) 出于安全原因,我建议在PHP中(在服务器端)使用电子邮件验证,因为绕过客户端非常容易(一个例子是著名的cURL库)

In PHP Email validation can be done this way : 在PHP中,可以通过以下方式完成电子邮件验证:

$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}

Source: http://www.w3schools.com/php/php_form_url_email.asp 来源: http//www.w3schools.com/php/php_form_url_email.asp

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

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