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

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


A simple popup HTML form when submits need to do two actions. 1. Send customer information to the existing database 2. Redirect customer to Thank you page.

提交时,一个简单的弹出HTML表单需要执行两个操作。 1.将客户信息发送到现有数据库2.将客户重定向到感谢页面。

With the help of another Stackoverflow member were able to work on this code. 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!

在另一个Stackoverflow成员的帮助下,能够处理此代码。但是,代码不起作用。我觉得我在做一些非常错误的代码,抱歉无法搞清楚。请帮忙!

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. 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? Thanks

我更喜欢使用Jquery,我不太熟悉PHP,如果有人可以指导我,我也可以实现PHP。即使在电子邮件地址输入中没有输入任何内容,表单也会被重定向。有没有办法告诉客户输入有效的电子邮件地址,然后带他到Thankyou页面?谢谢

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

    <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:

 <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:

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;

}

2 个解决方案

#1


0  

$(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 />

#2


0  

Use input type="email" Easiest Email Validation but only works in modern browsers http://www.w3schools.com/html/html5_form_input_types.asp

使用input 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


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/09/18/19da79a55791feb4c639ce03b67dde70.html



 
  © 2014-2022 ITdaan.com 联系我们: