Jump to content

HTTP_REFERER Page in Contact Form


Travist6983

Recommended Posts

I am pulling my hair out here i want to send the page that the contact form was sent from. 

 

I have looked at a 1000 articles about how to do this (Not very good in PHP) But it isnt working for me. 

 

Here is the code for my form page 

<header>
<img src="images/header.png"/>		
</header>
	<div id="page-wrap">
		
		<div id="contact-area">
			
			<form method="post" action="contactengine.php">
				<label for="Name">Name:</label>
				<input type="text" name="Name" id="Name" />
				
				<label for="City">Market:</label>
				<input type="text" name="Market" id="Market" />
	
				<label for="Email">Email:</label>
				<input type="text" name="Email" id="Email" />
				
				<input type="hidden" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" name="Page" />

				<input type="submit" name="submit" value="Submit" class="submit-button" />
			</form>
			
			<div style="clear: both;"></div>
		
		</div>
	
	</div>

And here is the file that i am posting too...

 


<?php

$EmailFrom = "sample@gmail.com";
$EmailTo = "sample@gmail.com";
$Subject = "Contact Form";
$Name = Trim(stripslashes($_POST['Name'])); 
$Market = Trim(stripslashes($_POST['Market'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Page = $_POST['Page']; 


// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Market: ";
$Body .= $Market;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Page: ";
$Body .= $Page;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to landing page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">"; //Edit here for Landing Page 
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Everything is being populated on the email that is being sent except $Page which is the hidden field on the form. 

 

Am i missing a ";" somewhere that is breaking it? I am lost any help would be appreciated!

 

Thanks in advance!

Edited by Travist6983
Link to comment
Share on other sites

If you view source of the form page what does the hidden field look like? If the hidden field is empty are you following a link from a non-https page to get to your form. The referer is empty if you type the address into the bar directly, use a bookmark, and is stripped by some security software. I tested the form as posted and it looks like it is working.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.