Link to home
Start Free TrialLog in
Avatar of Govinda
Govinda

asked on

How to go back to respective previous screen ?

Set up:
OS : Windows NT 4.0
Web server : Netscape Enterprise server
CGI scripts : Perl

Note : Not using Java script or VB script.

Problem description :
I have to add record to the database. From two different place user can come to add screen, after user pressing commit button it has to go back to the previous screen from where it came to add screen.

By pressing submit button (only) one script will be called this script should handle commit of the record to the database as well to generat the previous screen. How to do this ?

If I keep all the code required to generate the previous screen in the add-commit scripts it is not good way of doing it.

Other way is, in add-commit script execute the respective script (previous scripts). If it is good way then can any one tell me how to do it in perl script with small example ?.

Add-commit script has to do,
1. Validate the form fields (add screen's)
2. If error, generate add screen again and exit
3. If correct, insert a record to database
4. Generate previous screen (dynamically) by executing that script in add-coomit script.

Doubt : Is one perl script can execute another perl script in the CGI scripting without any problems (like security) ?


other good solution are expecting from experts with implementation details.
Avatar of icd
icd

If I understand correctly, you have one script that handles input from two different input forms. You want to put a 'back' button on the results page of the script to go back to where you came from.

One way you can do this is to have a hidden field in each of the input forms.

<input type="hidden" name="backto" value="/yourdomain.com/thispage.html">

(Changing the 'value' of course to point to the url of each page).
You can then use this value in your script to provide the url in the 'back' button.

Avatar of Michel Plungjan
Why no javascript?

Michel
Avatar of Govinda

ASKER

Hi icd,
I have to have hidden variable to know from where i came to add screen (as u suggested). But my question is, in the add screen user will give the data, this data has to be validated and inserted in the db (if very thing is ok). After that it has to generate previous screen, actuall it has to show all the record even newly inserted record.

Note : Two previous screens are generated by a script not static HTMLs.

How to implement ?
Avatar of Govinda

ASKER

Edited text of question
Avatar of Govinda

ASKER

Edited text of question
How about making the script that generates the 'previous' screen a subroutine? That way you don't need to include the same code in two different scripts.

The files would then be:-

routine.pm   Your script to generate the 'previous' screen
original.pl  Simple script that 'requires' routine.pm and calls it to generate the page.
validate.pl  Validate your input, 'require' routine.pm and calls it if necessary.

I assume you are using Perl 5.

One other possibility. Just have one script.

First time through (detected by cgi variables, i.e. no 'submit' cgi variable) the script outputs the screen showing the database data together with the form.

The 'action' part of the form data output by this script simply refers to its own URL.

On finding an input cgi variable associated with the 'submit' button the script can validate the data, update the database and output the data.

On finding an error it can output an alternative page explaining the error.

Put the various output functions in subroutines to make the code easier to follow.


Use the HTTP_REFERER to see where the form was submitted and redirect in you cgi script the user back to that url.


Why not do a JS history.go(-1) ?
ASKER CERTIFIED SOLUTION
Avatar of RoboBob
RoboBob

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Govinda

ASKER

Thanks a lot to every one.
Problem being solved long back because of
project pressure i forgot this, I am sorry for the delay.

Thanks,
Govinda