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
How to simulate the back button of the browser in php
Moderator: General Moderators
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.
I'll dig out some code if that doesn't make sense.
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"); }
?>-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
JavaScript histry(-1) donesn't work
I can not get old data in perious form if I use history(-1). Who knows how come?
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
<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
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
