我正在尝试使用表单(目前使用formoid)学习PHP并遇到问题。我按照我看过的教程,没有任何工作(正确)。我有一个简单的重定向脚本,我打算用它来将某个人重定向到一个页面" verified.html"如果他们输入正确的ID和(六位数)日期,并且输入" no.html"如果他们不这样做。但是,我试图这样做的两种方式都不起作用。当我使用这种方法时:
<?php
if (isset($_POST['submit'])){
$id = $_POST['trid'];
$date = $_POST['trdate'];
}
if ($id == '555555' && $date =='080808') {
header("Location: http://example.com/Form/verified.html");
exit();
} else {
header("Location: http://example.com/Form/no.html");
exit();
}
?>
该页面重定向到&#34; no.html&#34;在表格加载之前。阅读完另一个教程后,我想我必须在&#34; IF(isset&#34;语句)中包含两个IF语句。所以如果我这样做并使用这个方法:
<?php
if (isset($_POST['submit'])){
$id = $_POST['trid'];
$date = $_POST['trdate'];
if ($id == '555555' && $date =='080808') {
header("Location: http://example.com/Form/verified.html");
exit();
} else {
header("Location: http://example.com/Form/no.html");
exit();
}
}
表单实际上会加载,但无论我输入什么内容并提交,它都不会重定向到任何地方。我昨天晚上都在努力解决这个问题并摆弄不同的解决方案,我想出的所有内容都会导致表单没有被加载,或者它被加载然后没有重定向输入。如果有人能指出我正确的方向,那将是非常棒的。这是表单页面的代码,如果它是相关的(我在开头包含redirect.php,因为如果我把它包含在别处我得到一个关于header()已经被发送的错误):
<?php
include "redirect.php";
?>
<html>
<head>
<meta charset="utf-8" />
<title>Verify</title>
<meta name="viewport" content="width=device-width, initial- scale=1.0">
</head>
<body class="blurBg-false" style="background-color:#EBEBEB">
<!-- Start Formoid form-->
<link rel="stylesheet" href="formoid_files/formoid1/formoid-solid-blue.css" type="text/css" />
<script type="text/javascript" src="formoid_files/formoid1/jquery.min.js"></script>
<form action="validate.php" class="formoid-solid-blue" style="background-color:#FFFFFF;font-size:14px;font-family:'Roboto',Arial,Helvetica,sans-serif;color:#34495E;max-width:480px;min-width:150px" method="post"><div class="title"> <h2>Patient Verification</h2></div>
<div class="element-input"><label class="title">Please enter the six digit ID below:</label><div class="item-cont"><input class="large" type="text" name="trid" id="trid" placeholder="Input Number"/><span class="icon-place"></span></div></div>
<div class="element-input"><label class="title">Please enter the six digit year MMDDYY below:</label><div class="item-cont"><input class="large" type="text" name="trdate" id="trdate" placeholder="Input Number"/><span class="icon-place"></span></div></div>
<div class="submit"><input type="submit" value="Submit"></div></form>
<p class="frmd"><a href="http://example.com/v29.php">form builder</a> Formoid.com 2.9</p><script type="text/javascript" src="formoid_files/formoid1/formoid-solid-blue.js"></script>
<!-- Stop Formoid form-->
</body>
</html>
答案 0 :(得分:0)
看起来你的样子$_POST['submit']
已被设定,但你没有名字=&#34;提交&#34;在你的按钮元素上。为什么不使用......
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$id = $_POST['trid'];
$date = $_POST['trdate'];
if ($id == '555555' && $date =='080808') {
header("Location: http://example.com/Form/verified.html");
exit();
} else {
header("Location: http://example.com/Form/no.html");
exit();
}
}
答案 1 :(得分:0)
使用以下内容替换html页面中的表单:
<form action="validate.php" class="formoid-solid-blue" style="background-color:#FFFFFF;font-size:14px;font-family:'Roboto',Arial,Helvetica,sans-serif;color:#34495E;max-width:480px;min-width:150px" method="post"><div class="title">
<h2>Patient Verification</h2></div>
<div class="element-input">
<label class="title">Please enter the six digit ID below:</label>
<div class="item-cont">
<input class="large" type="number" name="trid" id="trid" placeholder="Input Number"/>
<span class="icon-place"></span>
</div>
</div>
<div class="element-input">
<label class="title">Please enter the six digit year MMDDYY below:</label>
<div class="item-cont">
<input class="large" type="number" name="trdate" id="trdate" placeholder="Input Number"/>
<span class="icon-place"></span>
</div>
</div>
<div class="submit"><input type="submit" name="submit" value="Submit"></div>
</form>
和php用这个:
<?php
if (isset($_POST['submit'])){
$id = $_POST['trid'];
$date = $_POST['trdate'];
if ($id == '555555' && $date =='080808') {
header("Location: http://example.com/Form/verified.html");
} else {
header("Location: http://example.com/Form/no.html");
}
}
?>
检查一下,让我知道结果。
答案 2 :(得分:-1)
尝试使用:
<?php
if (isset($_POST['submit'])){
$id = $_POST['trid'];
$date = $_POST['trdate'];
}
global $id, $date;
if ($id == '555555' && $date =='080808') {
header("Location: http://example.com/Form/verified.html");
exit();
} else {
header("Location: http://example.com/Form/no.html");
exit();
}
?>