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 联系我们: