我創建了Err代碼,因此必須檢查名稱和廣播,否則它不能移動到確認頁面並在該字段旁邊發送錯誤消息。如果我錯過任何代碼,請幫助!PHP驗證失敗
<?php
$nameErr = $charityErr = "";
$name = $charity = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is missing";
}
else {
$name = $_POST["name"];
}
if (!isset($_POST["charity"])) {
$charityErr = "You must select 1 option";
}
else {
$charity = $_POST["charity"];
}
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link type="text/css" href="testStyle.css" rel="stylesheet"/>
<title>Survey</title>
</head>
<body>
<div><!--start form-->
<form method="post" action="submit.php">
<input type="radio" name="charity" <?php if (isset($charity) && $charity == "1") echo "checked"; ?> value="1">1
<input type="radio" name="charity" <?php if (isset($charity) && $charity == "2") echo "checked"; ?> value="2">2
<input type="radio" name="charity" <?php if (isset($charity) && $charity == "3") echo "checked"; ?> value="3">3
<span class="error"><?php echo $charityErr;?></span>
<input type="text" name="name" placeholder="ENTER YOUR COMPANY NAME">
<span class="error"><?php echo $nameErr;?></span>
<input type="submit" name="submit" value="Submit"/>
</form>
</div><!--end form-->
</body>
</html>
我submit.php說:
/* Subject and Email Variables */
$emailSubject = 'Survey!';
$webMaster = '[email protected]';
/* Gathering Data Variables */
$name = $_POST ['name'];
$charity = $_POST ['charity'];
//create a new variable called $body line break, say email and variable, don't leave any space next to EOD - new variable $body 3 arrows less than greater than, beyond EOD no spaces
$body = <<<EOD
<br><hr><br>
Company Name: $name <br>
Charity: $charity <br>
EOD;
//be able to tell who it's from
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* Results rendered as HTML */
$theResults = <<<EOD
<html>
blah blah
</html>
這重定向罰款submit.php頁面除了我的驗證不起作用,並將空白數據。
表格上面的代碼是:
<form method="post" action="submit.php">
<input type="radio" name="charity"
<?php if (isset($charity) && $charity == "1") echo "checked"; ?>
value="1">1
<input type="radio" name="charity"
<?php if (isset($charity) && $charity == "2") echo "checked"; ?>
value="2">2
<input type="radio" name="charity"
<?php if (isset($charity) && $charity == "3") echo "checked"; ?>
value="3">3
<span class="error"><?php echo $charityErr;?></span>
<input type="text" name="name" placeholder="ENTER YOUR COMPANY NAME">
<span class="error"><?php echo $nameErr;?></span>
<input type="submit" name="submit" value="Submit"/>
</form>
很肯定收音機的問世略有不同。什麼'<?php print $ charity; ?>一旦你發佈了表單? – 2014-12-03 23:41:22
你可以輸出'echo'
';'在submit.php? – skobaljic 2014-12-03 23:45:02你如何收發電子郵件的結果? – Violin 2014-12-03 23:46:49