1つのHTMLページにある2つのフォームをPHPコードで処理させるにはどうすればいいですか?私はそれを働かせる方法をかなり理解しているのか分かりません。方法を探していたが、私は解決策を見つけ続けているようだ。1つのHTMLページにある複数のフォームをPHPで処理するにはどうすればいいですか?
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach ($_POST as $key => $value) {
$value = trim($value);
if (empty($value)) {
exit("Empty fields are not allowed. Please go back and fill in the form properly.");
} elseif (preg_match($exploits, $value)) {
exit("Exploits/malicious scripting attributes aren't allowed.");
} elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
exit("That kind of language is not allowed through our form.");
}
$_POST[$key] = stripslashes(strip_tags($value));
}
$recipient = "Contact Form <[email protected]>";
$subject = "New Message from Sample name";
$message = "Received an e-mail through your contact form: \n";
$message .= "Name: {$_POST['name']} \n";
$message .= "Address: {$_POST['address']}\r";
$message .= "City: {$_POST['city']} \r";
$message .= "State: {$_POST['state']} \r";
$message .= "Zip: {$_POST['zip']} \n";
$message .= "E-mail: {$_POST['email']} \n";
$message .= "Phone: {$_POST['phone']} \n";
$message .= "Message: {$_POST['message']} \n";
$from = 'Contact Form <[email protected]>';
// send email
$success = mail($recipient,$subject,$message,"From: " . $from);
if ($success) {
echo "success";
} else {
echo "Sorry, there was an error and your mail was not sent. Please contact me at <a href='#'>Email</a> or call me at <a href=''>Phone number</a>.";
}
}
?>
どうすればいいですか? – Qirel
POSTで送信している場合は、両方のフォームではなく、クリックした送信ボタンがあるフォームの情報のみが送信されます。 –
1つのフォームは評価フォームで、もう1つは連絡する基本名と電子メールフォームです。どちらも同じ送信ボタンHTMLを持ち、フォームにはそれぞれIDタグが割り当てられています。私はstackOverflowに新しいです。フォームはjsの検証を行っています。 –