我正在尝试编写一个脚本,如果你不选中一个复选框(在一个带有post方法的表单中),php脚本会将你发送到上一页(带有复选框的那个)并写入以检查复选框这是php脚本
PHP:
if(isset ($_POST["licencemessage"],$_POST["infomail"])){
$userreg=$_POST["signuser"];
$pwreg=$_POST["signpw"];
$cpwreg=$_POST["confirmpw"];
$minforeg=$_POST["infomail"];
require_once("signin1.php");
}elseif(isset ($_POST["licencemessage"])){
$userreg=$_POST["signuser"];
$pwreg=$_POST["signpw"];
$cpwreg=$_POST["confirmpw"];
$minforeg=0;
require_once("../signin1/signin1.php");
}else{
header("Location: {$_SERVER['HTTP_REFERER']}");
echo "EXCEPT CONDITIONS";
}
这是我想把php脚本带回上一页的地方:
else{
header("Location: {$_SERVER['HTTP_REFERER']}");
echo "EXCEPT CONDITIONS";
}
HTML复选框
<html>
<head>
<link type="text/css" href="css/css.css" rel="stylesheet">
</head>
<body>
<div id="headbar">
<img src="imgs/title.png" style="height:4em;float:left;"/>
<ul>
<li> <a class="linkheaderbar"></a> </li>
<li> <a class="linkheaderbar"></a> </li>
<li> <a class="linkheaderbar"></a> </li>
</ul>
</div>
<div id="bodypage">
<div id="formsign">
<form action="php/logtest/signin/roba/var.php" method="post">
<br>
USERNAME<br><input type="text" name="signuser" class="font_form"class="floatright"value="insert username"/>
<br><br>
PASSWORD<br><input type="password" name="signpw" class="font_form"value=""/>
<br><br>
CONFIRM PASSWORD<br><input type="password" name="confirmpw" class="font_form"value=""/>
<br><br>
MAIL<br><input type="text" name="signmail" class="font_form"value=""/>
<br><br>
show my mail in info (read eula)<input type="checkbox" name="infomail" class="font_form"value=""/>
<br><br>
i except the <a href="licence.html"class="randomlink">eula</a> conditions (please read it, there are only few rules) <input type="checkbox" name="licencemessage" class="font_form"value=""/>
<br><br>
or just <a href="doc.html"class="randomlink"> log in</a><br>
<input type="submit" name="submit" class="scrittefont" value="JOIN US"/>
</form>
</div>
</div>
</body>
这是复选框:
i except the <a href="licence.html"class="randomlink">eula</a> conditions (please read it, there are only few rules) <input type="checkbox" name="licencemessage" class="font_form"value=""/>
<br><br>
答案 0 :(得分:0)
大多数人通过将表单提交到当前页面来解决此问题。在页面顶部,在生成任何HTML输出之前,会编写一个脚本来检测表单是否已提交并验证它。如果存在验证问题,则在生成HTML时会打印一条消息。如果没有验证问题,那么您可以将提交的数据转发到另一个脚本,或者只处理当前脚本中的数据。
或者,您可以按照您已尝试的方式执行此操作,但是当您重定向到上一页时,请将验证消息附加为GET参数。例如。 &#39;标题(&#34;位置:&#39; \ thepreviouspage.php?err =验证%20错误&#39;&#34;);&#39;。