Formdaki temel doğrulamalar tetiklenmiyor bile!php form bir sunucu üzerinde çalışıyor ancak başka bir sunucuda çalışmıyor
Yeni sunucudaki kodu diğer sunucudaki kodla bakıyor ve karşılaştırıyordum ve kodun aynı olduğunu biliyorum ... ve belki de contactInformationGoogle.php
formuna ulaşmaya çalışırken dizinde sorun var. şimdi, bu benim endişem bile değil. Benim endişem, bu nedenle, temel doğrulamalar, yani, form boş olduğunda bile, * First name is required
, vb her zamanki uyarıları tetikleyen değil mi ???
Diğer sunucuda tam olarak aynı formda çalışır! Ciddi saçlarımı yırtıyorum ... lütfen yardım edin!
Bu
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<title>Hotel</title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<style type="text/css">
.error {
color:red;
}
body {
padding-top: 146px;
padding-top:175px;
}
.language_choice_english {
padding-right: 1%
}
.language_choice_japanese {
padding-right: 3%;
}
</style>
</head>
<body>
<?php
session_start(); //allows use of session variables
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_SESSION['token']) && $_SESSION['token'] == $_POST['token']) {
$token = md5(uniqid(mt_rand(), true));
$_SESSION['token'] = $token;
if (empty($_POST["first-name"])) {
$firstNameErr = "First name is required";
} else {
$first_name = test_input($_POST["first-name"]);
}
if (empty($_POST["last-name"])) {
$lastNameErr = "Last name is required";
} else {
$last_name = test_input($_POST["last-name"]);
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
}
if (empty($_POST["message"])) {
$messageErr = "Message is required";
} else {
$message = test_input($_POST["message"]);
}
if(isset($first_name) && isset($last_name) && isset($email) && isset($message))
{
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
$_SESSION['message'] = $message;
include dirname(__FILE__)."/../../contactInformation.php";
exit;
}
}
else {
$token = md5(uniqid(mt_rand(), true));
$_SESSION['token'] = $token;
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<nav class="navbar navbar-default navbar-fixed-top">
<a class="brand pull-left" href="index.html">
<img id="Logo" src="./images/logo_72H.gif" alt="Hotel">
</a>
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><span id="overall_title">Daimaru Hotel</span><small id="description_of_city">Little Tokyo, Los Angeles, Downtown</small></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="about.html">About</a></li>
<li><a href="rooms.html">Rooms & information</a></li>
<li><a href="reserve.php">Book to Reserve</a></li>
<li><a href="location.html">Location Info</a></li>
<li><a href="additional.html">Additional Info</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div><!-- /.navbar-collapse -->
<ul class="nav navbar-nav navbar-right">
<p class="pull-right language_choice_english"><a href="contact.php">English</a></p>
<p class="pull-right language_choice_japanese"><a href="contact-ja.php"><span lang="ja">日本語</span></a></p>
</ul>
</div><!-- /.container-fluid -->
</nav>
<div id="main-container" class="col-xs-12">
<div>
<label>* Required fields</label>
</div>
<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<div class="form-group">
<label class="col-sm-2 control-label">* First Name</label>
<div class="col-sm-10">
<input class="form-control" name="first-name" id="first-name" placeholder="First Name" type="text" value="<?php if(isset($first_name)) { echo $first_name; }?>">
<?php if(isset($firstNameErr)) print ('<span class="error">* ' . $firstNameErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">* Last Name</label>
<div class="col-sm-10">
<input class="form-control" name="last-name" id="last-name" placeholder="Last Name" type="text" value="<?php if(isset($last_name)) { echo $last_name; }?>">
<?php if(isset($lastNameErr)) print ('<span class="error">* ' . $lastNameErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">* Email</label>
<div class="col-sm-10">
<input class="form-control" name="email" id="email" placeholder="Email" type="email" value="<?php if(isset($email)) { echo $email; }?>">
<?php if(isset($emailErr)) print ('<span class="error">* ' . $emailErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">* Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="2" placeholder="Please type in your message" name="message" id="message" value="<?php if(isset($message)) { echo $message; }?>"></textarea>
<?php if(isset($messageErr)) print ('<span class="error">* ' . $messageErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
<footer class="col-xs-12 roomsFooter">
<div class="row">
<div class="col-md-4">2015 Hotel -- All rights reserved</div>
<div class="col-md-4">Terms of Use</div>
<div class="col-md-4">Facebook/Twitter/Instagram </div>
</div>
</footer>
<script src="js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
DÜZENLEME ... şimdilik basit tutmak için çalışıyor ... google'ın recaptcha widget'ı olmadan formu olduğunu
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<title>Hotel</title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<style type="text/css">
.error {
color:red;
}
body {
padding-top: 146px;
padding-top:175px;
}
.language_choice_english {
padding-right: 1%
}
.language_choice_japanese {
padding-right: 3%;
}
</style>
</head>
<body>
<?php
session_start(); //allows use of session variables
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_SESSION['token']) && $_SESSION['token'] == $_POST['token']) {
$token = md5(uniqid(mt_rand(), true));
$_SESSION['token'] = $token;
if (empty($_POST["first-name"])) {
$firstNameErr = "First name is required";
} else {
$first_name = test_input($_POST["first-name"]);
}
if (empty($_POST["last-name"])) {
$lastNameErr = "Last name is required";
} else {
$last_name = test_input($_POST["last-name"]);
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
}
if (empty($_POST["message"])) {
$messageErr = "Message is required";
} else {
$message = test_input($_POST["message"]);
}
if(isset($first_name) && isset($last_name) && isset($email) && isset($message))
{
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
$_SESSION['message'] = $message;
include dirname(__FILE__)."contactInformation.php";
exit;
}
}
else {
$token = md5(uniqid(mt_rand(), true));
$_SESSION['token'] = $token;
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<nav class="navbar navbar-default navbar-fixed-top">
<a class="brand pull-left" href="index.html">
<img id="DaimaruLogo" src="./images/logo_72H.gif" alt="New Daimaru Hotel">
</a>
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><span id="overall_title">Daimaru Hotel</span><small id="description_of_city">Little Tokyo, Los Angeles, Downtown</small></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="about.html">About</a></li>
<li><a href="rooms.html">Rooms & information</a></li>
<li><a href="reserve.php">Book to Reserve</a></li>
<li><a href="location.html">Location Info</a></li>
<li><a href="additional.html">Additional Info</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div><!-- /.navbar-collapse -->
<ul class="nav navbar-nav navbar-right">
<p class="pull-right language_choice_english"><a href="contact.php">English</a></p>
<p class="pull-right language_choice_japanese"><a href="contact-ja.php"><span lang="ja">日本語</span></a></p>
</ul>
</div><!-- /.container-fluid -->
</nav>
<div id="main-container" class="col-xs-12">
<div>
<label>* Required fields</label>
</div>
<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<div class="form-group">
<label class="col-sm-2 control-label">* First Name</label>
<div class="col-sm-10">
<input class="form-control" name="first-name" id="first-name" placeholder="First Name" type="text" value="<?php if(isset($first_name)) { echo $first_name; }?>">
<?php if(isset($firstNameErr)) print ('<span class="error">* ' . $firstNameErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">* Last Name</label>
<div class="col-sm-10">
<input class="form-control" name="last-name" id="last-name" placeholder="Last Name" type="text" value="<?php if(isset($last_name)) { echo $last_name; }?>">
<?php if(isset($lastNameErr)) print ('<span class="error">* ' . $lastNameErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">* Email</label>
<div class="col-sm-10">
<input class="form-control" name="email" id="email" placeholder="Email" type="email" value="<?php if(isset($email)) { echo $email; }?>">
<?php if(isset($emailErr)) print ('<span class="error">* ' . $emailErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">* Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="2" placeholder="Please type in your message" name="message" id="message" value="<?php if(isset($message)) { echo $message; }?>"></textarea>
<?php if(isset($messageErr)) print ('<span class="error">* ' . $messageErr . '</span>'); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
<footer class="col-xs-12 roomsFooter">
<div class="row">
<div class="col-md-4">2015 Hotel -- All rights reserved</div>
<div class="col-md-4">Terms of Use</div>
<div class="col-md-4">Facebook/Twitter/Instagram </div>
</div>
</footer>
<script src="js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Ve ContactInformation.php
<?php
session_start();
$first_name = $_SESSION['first_name'];
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email'];
$message = nl2br($_SESSION['message']);
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$mail->addReplyTo($email, $first_name);
$mail->addAddress($email, $first_name);
$mail->addAddress('', 'Staff');
$mail->From = '';
$mail->FromName = 'Staff';
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Hotel Contact';
$mail->Body = "<table width='600'><tr><td colspan='2' height='20'><p style='text-align:center; font-size:20px; color:#ddd; padding:0px; margin:0px;'>Copy of Your Contact Form</p></td></tr>"
."<tr><td colspan='2' height='80' width='600'><p style='color:#d1502d;font-size:50px;text-align:center;padding:0px; margin:0px;'>Hotel</p></td></tr>"
."<tr><td colspan='2' height='60' width='600' style='text-align:center; color:#606060;font-size:20px;padding:0px; margin:0px;'>Address</td></tr>"
."<tr><td colspan='2' height='30' width='600' style='text-align:center;'><h3 style='color:#d1502d; '>Tag line</h3></td></tr>"
."<tr><td height='20' width='300'><p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'>Your First Name: </p></td><td height='20' width='300'> <p style='font-size:20px; color:gray; padding:10px; margin:0px;'>$first_name</p></td></tr>"
."<tr><td height='20' width='300'><p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'>Your Last Name: </p></td><td height='20' width='300'><p style='font-size:20px; color:gray; padding:10px; margin:0px;'>$last_name</p></td></tr>"
."<tr><td height='20' width='300'><p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'>Your Email Address: </p></td><td height='20' width='300'><p style='font-size:20px; color:gray; padding:10px; margin:0px;'>$email</p></td></tr>"
."<tr><td height='20' width='300'><p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'>Your Message:</p></td><td height='20' width='300'><p style='font-size:20px; color:gray; padding:0px; margin:10px;'> $message</p></td></tr></table>"
."<tr><td colspan='2' height='15' width='600'><p style=' text-align:center;padding:0px; margin:0px;'><a style='color:#d1502d;font-size:15px;text-align:center;padding:0px; margin:0px;text-decoration:none;'href=''>Visit Our Site</a></p></td></tr>";
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
if(!$mail->send()) {
header('location: url_of_contactError.html');
} else {
header('location: url_of_contactResult.html');
}
DÜZENLEME İKİ
Sadece çalıştı şimdi bu hakkın - kendinden php doğrulama ile bazı temel kodu: (işe yaradı !!!!)
<!-- Coloring error messages -->
<style>
.error {color: #FF0000;}
</style>
<?php
$nameErr = $emailErr = "";
$name = $email = "";
// Define Variables as Empty Values
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
}else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
}else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<p><span class = "error">* required field.</span></p>
<form method = "POST" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr><td>Name:</td>
<td><input type = "text" name = "name">
<span class = "error">* <?php echo $nameErr;?></span>
</td></tr>
<tr><td>E-mail: </td>
<td><input type = "text" name = "email"><span class = "error">* <?php echo $emailErr;?></span></td></tr>
<tr><td><input type = "submit" name = "submit" value = "Submit">
</td></tr>
</table>
</form>
<?php
echo ("<p>name is $name</p>");
echo ("<p>email address is $email</p>");
?>
e hata, bunun çalışmadığı sunucuda oturum açar? – RiggsFolly
@RiggsFolly, hata günlüklerine erişiminiz yok. mümkün değil. – user273072545345
Muhtemelen ev sahibinize FTP koyar ve onu ararsınız. Normalde orada – RiggsFolly