如果有人可以通过我的代码并找到可能的错误,我已经尝试了一切,但我找不到错误。我的表单验证得很好,但是当提交并重定向到下一页时,它只是重新加载......
<?php
$your_email ='(i have removed e-mail)';
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';
if(isset($_POST['submit']))
{
$name = $_POST['form-name'];
$visitor_email = $_POST['form-email'];
$subject_email = $_POST['form-subject'];
$user_message = $_POST['form-message'];
$user_id = $_POST['form-id'];
$telephone = $_POST['form-telephone'];
///------------Do Validations-------------
if(empty($name)||empty($visitor_email))
{
$errors .= "\n Morate popuniti polja ime i e-mail. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Pogresno unet e-mail!";
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n Verifikacioni kod je pogresno unet!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject = "Nova poruka: $subject_email";
$from = $_POST['form-name'];
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "Posetilac $name je poslao poruku sa web-sajta:\n".
"Ime: $name\n".
"Email: $visitor_email \n".
"Poruka: \n ".
"$user_message\n".
"Broj licne karte: $user_id\n".
"Broj telefona: $telephone\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body, $headers);
header('Location: slanje_uspesno.html');
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script language="JavaScript" src="js/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body>
<div id="header">
<div id="container_header">
<div id="logo"></div>
</div>
</div>
<div id="container_kontakt">
<div id="kontakt_email">
<div id="kontakt_middle">
<div id="forma">
<div class="errors_kontakt">
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='form_errorloc' class='err'></div>
</div>
<form id="form" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<ul id="form_list">
<li><label>Vaše ime:</label><input type="text" id="form-name" name="form-name" value='<?php echo htmlentities($name) ?>'/></li>
<li><label>Vaš e-mail:</label><input type="text" id="form-email" name="form-email" value='<?php echo htmlentities($visitor_email) ?>'/></li>
<li><label>Naziv poruke:</label><input type="text" id="form-subject" name="form-subject" /></li>
<li><label>Broj telefona:</label><input type="text" id="form-telephone" name="form-telephone" maxlength="12" /></li>
<li><label>Broj lične karte:</label><input type="text" id="form-id" name="form-id" maxlength="6" /></li>
<li><label>Vaša poruka:</label><textarea name="form-message"><?php echo htmlentities($user_message) ?></textarea></li>
<li><label for="6_letters_code">Verifikacioni broj:</label><img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' > <input id="6_letters_code" class="captcha_code" maxlength="6" name="6_letters_code" type="text" ></li>
<li><label> </label><input type="submit" id="submit" value="POŠALJI" class="submit"></li>
</ul>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("form-name","req","Unesite Vaše ime");
frmvalidator.addValidation("form-email","req","Unesite Vašu e-mail adresu");
frmvalidator.addValidation("form-email","email","Unesite validnu e-mail adresu");
frmvalidator.addValidation("form-id","req","Unesite Vaš broj lične karte");
frmvalidator.addValidation("form-telephone","req","Unesite Vaš broj telefona");
frmvalidator.addValidation("6_letters_code","req","Verifikacioni kod je pogresno unet");
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</div>
</div>
<div id="footer">
</div>
</body>
</html>