Im currently building a contact form into a site but im having a slight niggle with it, when pressing refresh or using the back button onto that page, it will submit the form again once its already been submitted.
Ive heard about using sessions and using a hidden input field but im not sure the correct code for it, any help.
<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "test subject";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone = $_POST['phone'];
$location = $_POST['location'];
$body = "Name: $name_field\n E-Mail Address: $email_field\n Phone No: $phone\n Location:$location\n";
echo "<p>message sent</p>";
mail($to, $subject, $body);
} else {
echo "<p class='phone'>Fill in the form below or<br/> phone us : <strong>000000 000000</strong></p>";
}
?>
Ive heard about using sessions and using a hidden input field but im not sure the correct code for it, any help.
<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "test subject";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone = $_POST['phone'];
$location = $_POST['location'];
$body = "Name: $name_field\n E-Mail Address: $email_field\n Phone No: $phone\n Location:$location\n";
echo "<p>message sent</p>";
mail($to, $subject, $body);
} else {
echo "<p class='phone'>Fill in the form below or<br/> phone us : <strong>000000 000000</strong></p>";
}
?>