Page 1 of 1
How to simulate the back button of the browser in php
Posted: Thu Mar 20, 2003 3:27 pm
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
Posted: Thu Mar 20, 2003 5:56 pm
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.
Posted: Thu Mar 20, 2003 5:58 pm
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"); }
?>
Posted: Thu Mar 20, 2003 7:37 pm
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.
JavaScript histry(-1) donesn't work
Posted: Thu Mar 20, 2003 8:00 pm
by ups216
I can not get old data in perious form if I use history(-1). Who knows how come?
Posted: Thu Mar 20, 2003 8:58 pm
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
Posted: Fri Mar 21, 2003 11:54 am
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