如何在成功提交后使用基本的javascript弹出窗口显示“已提交”此表单?
<!DOCTYPE html>
<html>
<head>
<title>Site :: </title>
<link rel="stylesheet" media="screen" href="css/wicahost.css" />
<link rel="stylesheet" media="screen" href="css/global.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
<?php require_once('inc/php/clearfieldJs.php'); ?>
<script type="text/javascript">
$(document).ready(function() {
$("#splashtease").RSV({
rules: [
"required,emAdd,Please enter your email address.",
"valid_email,emAdd,Please enter a valid email address.",
]
});
});
</script>
</head>
<body>
<script src="http://www.benjaminkeen.com/software/rsv/jquery/jquery.rsv.js"></script>
<div id="splashTeaserBox">
<h1 class="wicasplashcenter">Signup!</h1>
<div class="wicasplashcenter">Captivating interests and inspiring collaboration.</div>
<form id="splashtease" action="inc/subscribe.php" method="post">
<?php $usrBrowser = $_SERVER['HTTP_USER_AGENT']; $todayDt = date('Y-m-d'); ?>
<input type="text" name="emAdd" class="splashtease" value="Your Email Address ..." onFocus="clearText(this)" />
<input type="hidden" name="brwsr" value="<?php echo $usrBrowser; ?>" style="margin:0; padding:0;" />
<input type="hidden" name="dt" value="<?php echo $todayDt; ?>" style="margin:0; padding:0;" />
<input type="submit" name="submit" value="" class="splashteasesub" />
</form>
</div><!--splashTeaserBox--></body>
</html>
PHP
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="dnbame"; // Database name
$tbl_name="subscriber"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
/* Obliterate bad input */
$goodEmail = mysql_real_escape_string($_POST['emAdd']);
$goodBrowser = mysql_real_escape_string($_POST['brwsr']);
$goodDate = mysql_real_escape_string($_POST['dt']);
$sql= "INSERT INTO subscriber (Email, Browser, DateSubscribed) VALUES('$goodEmail','$goodBrowser','$goodDate')";
$result = mysql_query($sql);
if (!$result) {
die('Invalid Email, please retry.');
}
else{
echo var success;
}
?>
答案 0 :(得分:0)
一个基本的例子:
在subscribe.php中,更改:
else{
echo var success;
}
为:
else {
echo "<html><body onload=\"alert('Submitted');\"><p>Submission successful.</p></body></html>";
}
答案 1 :(得分:0)
@ user886187的解决方案将在提交时重新加载页面,然后在页面重新加载时显示JavaScript弹出窗口。
您可能希望提交表单,然后显示弹出窗口而不重新加载页面。在这种情况下,您需要通过Ajax提交表单,然后在回调函数中提醒“提交”:
function callback() {
alert('submitted');
}
以下是如何通过Ajax提交表单的教程:
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
答案 2 :(得分:0)
将此代码放入您的subscribe.php
else {
header ('Location: formPage.php?message=Success');
}
并且此代码位于表单Page.php
的头部<head>
<?php if ($_GET['message']) {echo '<script type="text/javascript">alert("Form Submited Successfully");</script>';} ?>
</head>