【发布时间】:2018-04-01 15:57:05
【问题描述】:
我有一个 PHP 表单,它的操作链接是另一个 PHP 页面,它将用户输入的数据添加到数据库中。
另一个 PHP 页面正在寻找这个:
if (isset($_POST['submit'])) {
以前,在单击 sumbit/create 按钮后,在将 PHP 表单发送到其操作页面之前,我无法显示弹出窗口,因为一旦单击按钮,弹出框就不会出现。现在已在表单中的按钮标记上使用以下内容解决了这个问题(返回 false):
<button onclick="Alert.render('You are about to create a new group.'); return false" type="submit">Create</button>
现在我面临的问题是我无法将按钮链接到 php 页面,该页面会将用户输入的数据添加到数据库中。
我的代码:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
#dialogoverlay{
display: none;
opacity: .8;
position: fixed;
top: 0px;
left: 0px;
background: #FFF;
width: 100%;
z-index: 10;
}
#dialogbox{
display: none;
position: fixed;
background: #000;
border-radius:7px;
width:550px;
z-index: 10;
}
#dialogbox > div{ background:#FFF; margin:8px; }
#dialogbox > div > #dialogboxhead{ background: #666; font-size:19px; padding:10px; color:#CCC; }
#dialogbox > div > #dialogboxbody{ background:#333; padding:20px; color:#FFF; }
#dialogbox > div > #dialogboxfoot{ }
#dialogbox > div > #dialogboxfoot2{ }
</style>
<script>
function CustomAlert(){
this.render = function(dialog){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = (winW/2) - (550 * .5)+"px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Are you sure?";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">Cancel</button>';
document.getElementById('dialogboxfoot2').innerHTML = '<button onclick="Alert.ok(); document.getElementById(\'contact\').submit();" name="submit">Continue</button>';
}
function createForm()
{
Alert.render('You are about to create a new group.');
return false;
}
this.ok = function(){
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
}
var Alert = new CustomAlert();
</script>
<title></title>
<link rel="stylesheet" href="./css/form.css">
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div id="redirect"></div>
<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
<div id="dialogboxfoot2"></div>
</div>
</div>
<header>
<nav>
<div class="main-wrapper">
<div id="branding">
<li><h1><span><a href="homepage.php">ProjectNet</a></span></li>
</div>
<nav>
<ul>
<li><a href="homepage.php">Home</a>
<ul>
<li><a href="findGroup.php">Find A Group</a></li>
<li><a href="groupForm.php">Create A Group</a></li>
<li><a href="">Find New Members</a></li>
</ul>
</li>
<li><a href="">Members</a></li>
<li><a href="">Profile</a></li>
</ul>
</nav>
<div class="nav-login">
<?php
if (isset($_SESSION['u_id'])) {
echo '<form action="includes/logout.inc.php" method="POST">
<button type="submit" name="submit">Logout</button>
</form>';
} else {
echo '<form action="includes/login.inc.php" method="POST">
<input type="text" name="uid" placeholder="Username/Email">
<input type="password" name="pwd" placeholder="Password">
<button type="submit" name="submit">Login</button>
</form>
<a href="signup.php">Sign up</a>';
}
?>
</div>
</nav>
</header>
<section id="showcase1">
<div class="container">
<form id="contact" action="includes/form_process.php" method="POST">
<h3>Creating a Group</h3>
<h4>Please fill out the sections below.</h4>
<fieldset>
<input placeholder="Project title" type="text" name="name">
</fieldset>
<fieldset>
<textarea placeholder="Description of the project...." type="text" name="message" ></textarea>
</fieldset>
<fieldset>
<button onclick="return createForm()" type="submit">Create</button>
<!--name="submit"-->
</fieldset>
</form>
</div>
</section>
<footer>
<div class="wrapper">
<nav>
<ul>
<li><a href="about1.php">About</a></li>
<li><a>© 2018 ProjectNet</a></li>
</ul>
</nav>
</div>
</footer>
</body>
</html>
【问题讨论】:
标签: javascript php html forms popup