How to simulate the back button of the browser in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

How to simulate the back button of the browser in php

Post by lazy_yogi »

If a user fills out a form incorrectly I want to send them back to the form page. But instead of using header("Location :page.php) which sends them to a new version of the page, I want it to be the same as using the back button on the browser so that the form information is still there for them to modify.

Any idea how to simulate the back button of the browser in php ?
or any other way.

Cheers
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Do the form script and the form processor in a single file / function. Start off by declaring all the $_POST vars. IF they're all there, update the database or whatever else you do with them. If not, display the form again. If you've set initial values for form fields in the code, you'll get all the previously submitted data.

I'll dig out some code if that doesn't make sense.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

All $_POST variables will be there, but be sure that they aren't empty.

Code: Select all

<?php
if(empty($_POST["var1"])) { die("You didn't fill in area 1"); }
?>
Image Image
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

If the form must be posted to another page, then check the values and
write out some javascript to do a history(-1) type thing.

Might be best to initially check the values on the page with the form using some javascript edits.....if in error, don't submit the form!

Phil J.
ups216
Forum Newbie
Posts: 3
Joined: Thu Mar 20, 2003 8:00 pm
Location: Sydney
Contact:

JavaScript histry(-1) donesn't work

Post by ups216 »

I can not get old data in perious form if I use history(-1). Who knows how come?
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Might be best to initially check the values on the page with the form using some javascript edits.....if in error, don't submit the form!
Hey fractalvibes, I don't know ANY javascript.
Do u have an example of that that I could see please

Cheers
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

<script language="javascript">
function validate(){
if(form_modify.agency_Name.value=="" || form_modify.agency_Name.value==" "){return false;}
else if(form_modify.agency_Number.value=="" || form_modify.agency_Number.value==" "){return false;}
else if(form_modify.agency_Address1.value=="" || form_modify.agency_Address1.value==" "){return false;}
else if(form_modify.agency_City.value=="" || form_modify.agency_City.value==" "){return false;}
else if(form_modify.agency_State.value=="" || form_modify.agency_State.value==" "){return false;}
else if(form_modify.agency_Zip.value=="" || form_modify.agency_Zip.value==" "){return false;}
else if(form_modify.agency_Type.value=="" || form_modify.agency_Type.value==" "){return false;}
else return true;//checks all pass
}
</script>
<form name="form_modify" action="" onclick="return validate()">
Form has fields named agency_Name, agency_Number, etc.
</form
Post Reply