POSTDATA problem with a PHP Form

Associate
Joined
2 Nov 2004
Posts
582
Location
London, UK
Tonight I have been trying to tidy up my contact form a bit, but having got the form sorted, my PHP seems to have gone wrong somewhere along the way. The actual script is unchanged, but it seems to have developed an annoying problem whenever the page is refreshed. A warning message pops up containing:

"The page you trying to view contains POSTDATA. If you resend the data..."

I cant pretend to know much about the PHP, but I can just about follow how this script works (ish).

PHP:
<?php
// Configuration Start \\
$YourEmail = "[email protected]";
$YourSubjects = array("General Enquiry","Hire","Site Comment","Other");
//  Configuration End  \\

if($Submit)
{
    if(empty($email) || empty($name) || empty($message))
    {
        echo "<p class=alert>** You forgot to enter some of the required fields. Please go back and make sure you entered all the fields correctly. **</p>";
    }
    elseif(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email))
    {
        echo "<p class=alert>** The e-mail is not valid. Please go back and try again. **</p>";
    }
    else
    {
        $Message = "$name has contacted you with Subject: $Subject. The message is below.\n\n***************\n$message\n***************\n\nIP of sender: $_SERVER[REMOTE_ADDR]\nE-mail of sender: $email";
        $headers = 'From: ' . $email . "\r\n" .
           'Reply-To: ' . $email . "\r\n" .
           'X-Mailer: PHP/' . phpversion();
        mail($YourEmail, $Subject, stripslashes($Message), $headers);
        echo "Your E-Mail has been successfully sent. Thankyou for taking the time to contact us, we will try and reply as soon as possible.";
    }
}
else
{
    echo '							
	 								   <form name="cf" method="post" action="">

										<label for="name">Your Name:</label>
										<input type="text" id="name" name="name" value="" /><br />

										<label for="email">Email Address:</label>
										<input type="text" id="email" name="email" value="" /><br />

										<label for="locn">Subject:</label>
										<select class="subject" name="Subject">
										';
  												  foreach($YourSubjects as $Subject)
    													{
     													   echo '<option>' . $Subject . '</option>';
  													  	}
  										  echo '
										</select>

										<label for="message">Message:</label>
										<textarea name="message"></textarea>

										<input type="submit" name="Submit" class="submit" value="Send" /><input class="reset" type="reset" name="Reset" value="Reset" /><br />

										</form>
										
';}?>
If anyone can spot anything thats wrong, I would be extremely grateful if you could point it out. I havent a clue where to start looking. If it helps in any way, I can upload the relevant files.

Any help would be much appreciated :)
 
That's nothing to do with the script, that's a standard warning given by your browser when you try to refresh a page load which also submitted a POST form, because the POST method is used to perform an action on the server (in this case sending an e-mail), so by refreshing the page you cause it to be sent again.

Nothing unusual there, though I haven't looked at your code at all since it's not relevant to this little error. Maybe your last code redirected the visitor to another page after sending, so refreshing *that* page wouldn't cause the message :)
 
Beansprout said:
That's nothing to do with the script, that's a standard warning given by your browser when you try to refresh a page load which also submitted a POST form, because the POST method is used to perform an action on the server (in this case sending an e-mail), so by refreshing the page you cause it to be sent again.

Nothing unusual there, though I haven't looked at your code at all since it's not relevant to this little error. Maybe your last code redirected the visitor to another page after sending, so refreshing *that* page wouldn't cause the message :)
OK, thanks. Im stumped then :confused: I thought I had copied it exactly.

Here are the 2 pages in question:

http://www.simplestuff.co.uk/contact.php - Original
http://www.simplestuff.co.uk/contact2.php - Tidied up version with dodgy warning

EDIT
Everything seems to be hunky dorey now, strange :confused:
 
Back
Top Bottom