Wie kann ich meinen PHP-Code verarbeiten 2 Formulare, die auf einer HTML-Seite sind. Ich bin mir nicht sicher, ob ich recht verstehe, wie ich es zur Arbeit bringen kann. Auf der Suche nach einem Weg, aber scheint ich immer mehr Fehler als Lösungen zu finden.Wie mache ich meinen PHP-Prozess mehrere Formulare, die auf einer HTML-Seite sind
<?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>.";
}
}
?>
Was sollen die verschiedenen Formen tun? – Qirel
Wenn Sie über POST senden, werden nur die Informationen in dem Formular gesendet, auf das Sie geklickt haben, nicht auf beide Formulare. –
Ein Formular ist ein Bewertungsformular und das andere ist ein Basisname und ein E-Mail-Formular, das kontaktiert werden muss ... beide haben denselben HTML-Sende-Button und die Formulare sind jeweils mit einem ID-Tag versehen. Tut mir leid, ich bin neu in StackOverflow. Die Formulare durchlaufen die Validierung. –