Jump to content
Larry Ullman's Book Forums

Trying To Return To Previous Page From A Form


Recommended Posts

<?php

$returnurl = htmlspecialchars($_SERVER['HTTP_REFERER']);

 

if(!preg_match('/formpage.php/', $returnurl)) {

echo "<p><a href=\"$returnurl\"><img id=\"lftarrow\" src=\"images/LhArrow.graphic.png\" alt=\"Previous page\">Return</a></p>";

} else {

echo "<p><a href=\"index.html\"><img id=\"lftarrow\" src=\"images/LhArrow.graphic.png\" alt=\"Home page\">Return to Home page</a></p>"; }

?>

 

I am using this code to provide a path back to the calling page from the page with a form.

 

My problem is that the form calls its own page in <form method='post' action='formpage.php'> negating what I had hoped to be an elegant return path for the user - hence the if/else defaulting to a fixed url.

 

Is there anyway of preserving the value of $returnurl whilst the form processes?

 

Thank you

 

PS Posted here as I was playing with techniques tried from this book - hope that is correct

Link to comment
Share on other sites

 Share

×
×
  • Create New...