即使先前的表单不正确,也会发送到标题位置

时间:2013-09-09 15:35:29

标签: php

我有下面的代码设置。用户只需输入他们的电子邮件地址,单击提交按钮,然后进入下一页。问题是,即使他们没有输入电子邮件,它仍然会将他们带到那个页面我知道它可能是一个愚蠢的错误,但我似乎无法发现它。

?php
include('header.php');
include('side.php'); ?>

<div id="content">

<?php
if($_SESSION['uid'] != 1)

echo '
<h2>Alpha Registration</h2>
<p align="center">Registration for an Alpha Account costs &#163;5.<br>You will be asked to confirm and pay on the following page.</p>
<form method="post" action="alpharegister.php">
<div id="loginform"><center><table>
<tr><td>Email:</td><td><input type="text" class="box" name="email"></td></tr>
<tr><td colspan="2"><center><input type="submit" class="submit" name="registersubmit" value="Begin Registration"></center></td></tr>
</table></center></div></form>';

else {
}

if($_POST['registersubmit'] && (isset($_POST['email'] && isempty($_POST['email'])){
$email = protect($_POST['email']);

if(!$email) {
echo '<div class="incorrectlogin">You must enter a valid email address.</div>';
}else{

$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";

if(!preg_match($checkemail, $email)) {
echo '<div class="incorrectlogin">You must enter a valid email address.</div>';
}else{

setcookie("AlphaEmail", $email, time()+3600);
header('Location: alpharegister.php');
}}}?>

EDIT 上面编辑的代码显示完整的index.php,包括下面建议的代码。

alpharegister.php

<?php
include('header.php');
include('side.php');
?>

<div id="content">
<h1>Alpha Account Registration</h1>

<?php
echo 'Your email is ' .$_COOKIE["AlphaEmail"]. '!';
?>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="FJP9C8CSJ73GG">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
</div>

1 个答案:

答案 0 :(得分:1)

添加了此附加条件语句,以检查电子邮件输入值是否输入

if($_POST['registersubmit'] && (isset($_POST['email']) && !isempty($_POST['email']) )) {
// do you stuff here
}