[英]HTML form Submission to Database and redirect to Thank you page
提交時,一個簡單的彈出HTML表單需要執行兩個操作。 1.將客戶信息發送到現有數據庫。2.將客戶重定向到“謝謝”頁面。
在另一個Stackoverflow成員的幫助下,他們可以處理此代碼。 但是,代碼不起作用。 我覺得我對代碼做了非常糟糕的事情,對不起無法弄清楚。 請幫忙!
當前,該表單已發送到數據庫,但是重定向到現有的郵件列表注冊頁面,如果我將操作更改為“謝謝”頁面,則該表單將發送給“謝謝”頁面,但沒有提交到數據庫。
我更喜歡使用Jquery,我對PHP不太熟悉,如果有人可以指導我,我也可以實現PHP。 即使在“電子郵件地址”輸入中未輸入任何內容,該表單也將被重定向。 有沒有辦法告訴客戶輸入有效的電子郵件地址,然后帶他到Thankyou頁面? 謝謝
數據庫地址:“ http://www.mywebsite.com/MailingList_subscribe.asp ”謝謝頁面地址:“ https://www.mywebsite.com/Articles.asp?ID=252 ”
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正文:
<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;
}
$(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
});
});
)};
並強迫用戶輸入有效的電子郵件,您可以使用
<input type=email />
代替
<input type=text />
使用輸入type =“ email”最簡單的電子郵件驗證,但僅在現代瀏覽器中有效http://www.w3schools.com/html/html5_form_input_types.asp
出於安全原因,我建議在PHP中(在服務器端)使用電子郵件驗證,因為繞過客戶端非常容易(一個例子是著名的cURL庫)
在PHP中,可以通過以下方式完成電子郵件驗證:
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.