|
Subject:
|
go back previous page
|
|
Posted By:
|
hosefo81
|
Post Date:
|
2/10/2004 10:56:56 PM
|
How am i going to code the php page to be able to go back a previous page. For example, if i have a employee.php where the user have to enter the name, address, phone, date of birth and etc. After the user clicked the submit button, the newemployee.php will checked if the user entered all the data before a new employee details will be entered in the database. If the user does not enter the date of birth, i want to go back to the employee.php page which display the previously uncompleted entered data.
|
|
Reply By:
|
Snib
|
Reply Date:
|
2/11/2004 9:51:04 AM
|
You could echo some javascript if the user fails:
if($success == "failure") echo "Failure.<script language=javascript>setTimeout('window.history.go(-1)',2000);</script>";
This is the method I use on my pages. HTH,
---------- ---Snib--- ----------
|
|
Reply By:
|
nikolai
|
Reply Date:
|
2/11/2004 12:50:45 PM
|
This is exactly why most PHP scripts that generate forms are also responsible for receiving and validating the input of those forms.
If all the input is valid, then you redirect to the page that will process (e.g. insert into database, etc) the data.
If any of the data is invalid, then you flag the fields that were invalid and regenerate the form with error messages.
What's nice about this approach is that you can pre-populate all the fields of the form that contained valid info -- this spares the user of having to fill in ALL the fields when only one or two of them might be bad.
Here's the flow of logic:
<?php
if (the user submitted data) { for each field in the form { is the user input valid? if not, add this field to your "error fields" list. }
if your "error fields" list is empty, { process the data (or redirect to your processing script) and exit. } }
// if we got here, we need to generate the form.
generate the form. Output any error messages and highlight any fields in your "error fields" list.
If any previously submitted data exists, populate the form fields with the submitted value. Don't do this for fields in your "error fields" list.
?>
Hope this makes sense!
Take care,
Nik http://www.bigaction.org/
|