...

View Full Version : Redirect without losing information



Vidhya
03-27-2003, 07:07 AM
How to Redirect a page to the other page with the values in the text fields retained. i.e, Page 1 gets the information from the user, validates the information in the page 2 and it needs to redirect again to page 1, if the informations are not valid. Thnx. Bye

firepages
03-27-2003, 04:46 PM
easiest way is to do everything on page 1.. i.e. page1.htm has a form action of page1.htm , page1 itself decides if it is supposed to be processing or showing the form.



<?
if($_POST['submit']){
//process form//

//if process success
if(!$errors){
header('location:thanks.page');
exit();
}
}

//still here ? - show the form
?>
<form action="page1.htm"..
...
<input type="text" name="field" value="<?=$_POST['field'];?>">
etc



another way is to store all $_POST & $_GET data in a session which you can pass from page to page really easily.

so on page2.htm , process the form, if there are errors you can add the form data to a session & send back to page1 (or indeed anywhere else..



<?
session_start();
if($_POST['submit']){
//process form
//error occurs ?
$_SESSION['post_data']=$_POST;
header('location: page1.htm');
}?>

page1.htm ... if the post_data exists we can use it.

<?
session_start();
if($_SESSION['post_data']){
$_POST=$_SESSION['post_data'];
}
?>


etc



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum