提交 optin 表单后如何使 javascript 或 php 成功消息出现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29248959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a javascript or php SUCCESS message appear after optin form has been submitted
提问by Lost Sould
I am using a custom optin page with a form , Currently the form works like this USER SUBMITS > PAGE REFRESHES FOR HIM > I GET AN EMAIL WITH THE SUBMITTED DATA.
我正在使用带有表单的自定义 optin 页面,目前该表单的工作方式如下:用户提交 > 页面刷新给他 > 我收到一封包含提交数据的电子邮件。
But the user does not get a confirmation message, So most of the times , Users re submit the form thinking it did not worked at the 1st time.
但是用户没有收到确认消息,所以大多数时候,用户重新提交表单,认为它在第一次没有工作。
I want to add a Popup/Javascript Success Message to it ORAfter hitting submit , the user gets redirected to another page .
我想向它添加一个弹出/Javascript 成功消息或点击提交后,用户被重定向到另一个页面。
This is the current form code
这是当前的表单代码
<div class="form fix ">
<p class="form-text">Fill This Out and See Your <br>Timeshare Report</p>
<form name="contactform" action="mail-script.php" method="POST">
<label for="fname">First Name:
<input type="text" name="fname" id="fname" />
</label><br>
<label for="lname">Last Name:
<input type="text" name="lname" id="lname" />
</label><br>
<label for="email">Email Address:
<input type="text" name="email" id="email" />
</label><br>
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
</label><br>
<label for="resort">Resort Name:
<input type="text" name="resort" id="resort" />
</label><br>
<label for="amount">Amount Owed? $:
<input type="number" name="amount" id="amount" />
<p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">
If Paid Off Leave Zero, Else Put Amount</p>
</label><br>
<div class="checkbox">
<div class="check-text fix">
<p>I'm Considering To</p>
</div>
<div class="check-one fix">
<input type="checkbox" name="call" id="" value="sell"/> Sell It <br>
<input type="checkbox" name="call" id="" value="buy"/> Buy It <br>
<input type="checkbox" name="call" id="" value="rent "/> Rent It
</div>
<div class="check-two fix">
<input type="checkbox" name="call" id="" value="cancel"/> Cancel Mortgage <br>
<input type="checkbox" name="call" id="" value="ownership"/> End Ownership <br>
<input type="checkbox" name="call" id="" value="give"/> Give It Back
</div>
</div>
<p class="captcha">
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input id="submit" type="submit" value="" />
<p class="submit-text">Ensure all fields are completed and correct, allowing you more benefits, while preventing abuse of our data.</p>
</form>
</div>
</div>
This is the online url of the form http://timesharesgroup.com/sell/index.html
这是形式http://timesharesgroup.com/sell/index.html的在线网址
**********************UPDATE******************************
**********************更新*************************** ***
回答by callback
If you want just a normal pop up button, you could do the following :
如果您只想要一个普通的弹出按钮,您可以执行以下操作:
$('form').on('submit',function(){
alert('submitted');
});
If you want a fancier way to do things, you can use AJAX.
You could add to your HTML a hiddendiv
with id
success, and you do the following:
如果你想要一种更高级的做事方式,你可以使用AJAX。你可以添加到您的HTML中的隐藏div
与id
成功,而你做到以下几点:
<span class="success">Thank's for submitting the form</span>
and AJAX is :
和 AJAX 是:
$(document).ready(function() {
$("form[name='contactform']").submit(function() {
// do the extra stuff here
$.ajax({
type: "POST",
url: "mail-script.php",
data: $(this).serialize(),
success: function() {
$('.success').fadeIn(100).show();
}
})
})
})
回答by Navneeth
You can give appropriate message on form submit event through below function. you can even stop form submitting through event.preventDefault();
if you mentioned inside function.
您可以通过以下功能在表单提交事件上给出适当的消息。event.preventDefault();
如果您提到内部功能,您甚至可以停止表单提交。
$( "form" ).submit(function( event ) {
alert( "Handler for submit() called." );
window.location.href="another html page";
});
回答by Ramu
when a user click your url like www.site.com/index.php the form will coming. when a user fill the data and click on submit the url showing like this www.site.com/mail-script.php but i am asking Where is your code for mail-script.php
当用户单击您的网址(如 www.site.com/index.php)时,表单就会出现。当用户填写数据并单击提交显示如下所示的 URL www.site.com/mail-script.php 但我问你的 mail-script.php 代码在哪里
under this file bottom you can add this line of code.
在这个文件底部你可以添加这行代码。
header('Location: thankyou.php');
header('位置:thankyou.php');
and create your own thankyou.php file like this
并像这样创建自己的thankyou.php文件
<html>
<body>
<h1>Mail delivery success. Touch you soon...</h1>
</body>
</html>