在HTML和php中,有没有一种方法可以在几种模式之间移动并使用几种模式



我正在创建一个登录模式,其中包括一些用于注册、注销和更新注册的模式。处理所有模态的有效方法是什么?我的HTML主页是"index.php",如下所示。

<?php
/*
*  Programming Title Block
*/
…
include('account/registration/login_code.php');
?>
<!DOCTYPE html>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include("view/head.php"); ?>
</head>
<body class='homePage_bg'>
<?php include("view/header.php"); ?>
<?php include("view/nav.php"); ?>
<div class="content">
<?php include('account/registration/login.php'); ?>
<article>
…
</article>
</div>
<?php include("view/footer.php"); ?>
</body>
</html>

login.php文件需要更多的工作,但目前看起来是这样的:

<!-- The Modal -->
<div id='id01' class='modal'>
<span onclick="document.getElementById('id01').style.display='none'"
class="close" title="Close Modal">&times;</span>
<!-- Modal Content -->
<form class="modal-content animate" method='post' action=''>
<div class='modal-header'>
<h2>Member Login</h2>
</div>
<div class="container">
<label><i class="fas fa-user"></i> Name</label>
<input type='text' class='form-control' name='username' />
<label><i class="fas fa-lock"></i> Password</label>
<input type='password' class='form-control' name='password' />
</div>
<div class='modal-footer'>
<input type='submit' class='btn btn-default' name='login' data-dismiss='modal' value='Login' />
<input type='button' class='btn btn-primary' name='cancel' value='Cancel' 
onclick="document.getElementById('id01').style.display='none'" />
</div>
</form>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
}
};
</script>
</div>

"index_code.php"文件如下:

<?php
if(!isset($_SESSION)){
session_start();
}
/*
*  Programming Title Block
*/
require_once('model/name_db.php');
$dbna = new dbName();
$_SESSION['$Registration_ID'] = null;
unset($_SESSION['$Registration_ID']);
if(filter_input(INPUT_POST, 'login')) {
// username and password sent from form
$userName = "'" . filter_input(INPUT_POST, 'username') . "'";
$password = "'" . filter_input(INPUT_POST, 'password') . "'";
try {
list($name, $message1) = $dbna->get_name_by_userName_and_password($userName, $password);
$message .= $message1;
if(!$name) {
$message .= "There was no matching User-Name and Password.";
}
else {
$_SESSION["RegName_ID"] = $_SESSION["Name_ID"] = $nameID = $name['name_id'];
$_SESSION["Security_ID"] = $name['security_id'];
$_SESSION["fullName"] = $full_Name = $name['namefull'];
}
} catch(PDOException $e){
$message .= $sql . "<br />" . $e->getMessage().'<br />';
}
header('Location: index.php');
}
?>

以前我有一个Login.php文件,与主页index.php处于同一级别。在该文件中,我将这些php包含在编码的php部分和HTML部分。

<?php
…
include 'account/registration/LoginIndex_code.php';
?>
<!DOCTYPE html>
…
<?php include 'account/registration/LoginIndex.php'; ?>
…
The 'account/registration/LoginIndex.php' was as follows:
<?php //
/* 
* Programming Title Block
*/
if(filter_input(INPUT_GET, 'action')) {
$action = filter_input(INPUT_GET, 'action');
}
switch ($action) {
case 'login':
include('login.php');
break;
case 'regName':
include('regName.php');
break;
case 'regAddress':
include('regAddress.php');
break;
…

前一段代码的问题是我使用URL操作变量来更新登录模式的状态。因此,模态并不是作为一个模态,而是作为一个HTML网页。谢谢你看这个。

我修改了nav.php文件,使其能够登录并下拉菜单进行注销和更新注册。

...
<?php if(!$full_Name){ ?>
<a class="btn rightBtn" id='login'
onclick="document.getElementById('id01').style.display='block'" >Login</a>
<?php } else { ?>
<div class="dropdown">
<button class="dropbtn">Logout
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a class="btn rightBtn" id='logout'
onclick="document.getElementById('id99').style.display='block'" >Logout</a>
<a class="btn" href="Login.php?action=updateName">Update Name</a>
</div>
</div>
<?php } ?>
...

登录模式现在包括注册选项

...
<div class='modal-footer'>
<input type='submit' class='btn btn-default' name='login' data-dismiss='modal' value='Login' />
<input type='button' class='btn' name='cancel' value='Cancel' 
onclick="document.getElementById('id01').style.display='none'" />
<input type='button' class='btn' name='signup' value='Sign-Up' 
onclick="location.href='Login.php?action=regName'" />
</div>
...

总之,网站的每个页面现在都包含用于登录和注销的模式代码,状态由onclick控件切换为显示或不显示。Registration和Update Registration由switch语句索引,相关代码被调用到根目录下的Login.php文件中。switch语句读取URL的操作。

相关内容

最新更新