我有一个带有authController的表单页面用于验证。 以下是表单页面的代码:
<div class="main-content">
<h3>log in as student</h3>
<h3>
<!-- SHOW URL MESSAGE HERE -->
</h3>
<form action="../app/controllers/authController.php" class="login_form" method="POST">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" id="" class="input_field">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="" class="input_field">
</div>
<div class="form-group">
<input type="submit" name="type" id="" value="Log In" class="btn btn-info">
</div>
</form>
</div>
以下是authController的代码:
if ($_POST['type'] == 'Log In') {
if (! Validator::notEmpty()->validate($_POST['username']) ||
! Validator::notEmpty()->validate($_POST['password'])) {
$err_msg = "One of the fields is empty";
$user->redirect('stu_login.php?type=' . $err_msg);
exit;
}
如何在$err_msg
所在的表单页面上显示authController中定义的<!-- SHOW URL MESSAGE HERE -->
?
答案 0 :(得分:1)
替换
$user->redirect('stu_login.php?type=' . $err_msg);
要
$user->redirect('stu_login.php?msg=' . $err_msg);
并像stu_login.php一样使用
<h3>
<!-- ERROR OR OTHER MESSAGE -->
<?php
if(isset($_GET['msg'] != '')
echo $_GET['msg'];
?>
</h3>