私はシンプルなPHP購読フォームを書いています。実行すると何もしません。PHPベースの形式ではコンテンツが送信されませんか?新鮮な目を探しています
<form class='subscribe' method='post' action='<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>'>
Subscribe for occasional updates and reminders!
Email: <input type='text' class='input' name='email' id='email' >
<!--There will be some type of CAPTCHA here-->
<label for='Subscribe'>
<input value='Subscribe' type='submit' id='subscribebutton' class='input' name='subscribebutton'>
</label>
<span class='error'><?php echo $inError ?> </span>
<?php
$email = '';
$inError = '';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(empty($_POST['email']))
$inError = "You must provide an email to register!";
elseif(stripos($_POST['email'],'@') !== TRUE || stripos($_POST['email'],'.') !== TRUE)
$inError = "Please provide a properly formatted email to register.";
else
{
$email = sanatizeInput($_POST['email']);
$emailFile = fopen('emails.txt','a') or die ('Sorry. Subscriptions are disabled for the time being.');
fwrite($emailFile, $email);
}
}
function sanatizeInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
ノーコンテンツや不適切な形式のコンテンツでフォームを送信する場合には、エラーを投げていない
は、それがファイルを書いていない、私が送信ボタンを押したとき、それは正確に何もしないだと思わ (:PHPは、このようになりますフィールドをクリアしてフォームを提出するように見えますが)。
これはおそらく単純なものですが、私の目はそれを完全に見逃しています。
ご協力いただければ幸いです。
ありがとうございます。 ザック
'stripos(...)!== TRUE'は決して動作しません。 striposは、見つかった文字列の整数インデックス、またはブール値falseを返します。 ** TRUEを返すことは決してできないので、あなたの 'if()'はいつも成功するでしょう。 –