Forum Moderators: coopster & phranque

Message Too Old, No Replies

Page refresh issue

How can I tell if it's a refresh?

         

enchant

4:51 pm on Jul 1, 2004 (gmt 0)

10+ Year Member



I have a multi-page form. On page one, the user enters some information and clicks "next". The information collected on page 2 of the form depends on what they entered on page 1.

So when the "page 2" script is run, the information passed from page 1 is entered into a database first, then the dynamic fill-in form is generated.

This works fine, except that if they're on page 2 and hit the refresh button for some reason, the page 1 information is again entered into the database as an additional record.

Is there some simple way for a perl script to "know" that it's being run from a refresh, as opposed to being run for the first time? I could figure out some code to write a unique temporary file of some sort, but if there's an easier way...

Thanks for any help.

jatar_k

5:12 pm on Jul 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What we do to stop multiple inserts is generate the id at the beginning of the transaction and then pass that along through out. This way you can use the id to check if those values exist before you insert them.

You won't insert dupe rows and you can add on to the existing row easily.

enchant

8:07 pm on Jul 1, 2004 (gmt 0)

10+ Year Member



I'm currently starting with a simple HTML file to collect the initial information. To do it the way you mentioned, I'd have to use a script, right?

bsterz

8:31 pm on Jul 1, 2004 (gmt 0)

10+ Year Member



Obviously I'm not clued in to the entire scope of your project, but here is what I do when I have to do a write in the middle of a multi-step process:

Collect data
Verify data
write data
query data
display data
collect the next set of data
Start the whole hokey-pokey over again

One reason I do this is I find it hard to reliably determine if they hit refresh, hit the back button and came forward again, opened a new window at the page, on and on. This way, I can drop a visitor into the process at any point and collect data.

So:
Form1.php collects his first name and last name
WriteAndShow.php receives the values, writes them to the db, and redirects to a page (could be the same page with a parm) that displays them with whatever other fields you need filled out. If they refresh this page, it only shows them what they already filled out and prompts them for what is needed.

Hope this helps.

Bill

enchant

8:56 pm on Jul 1, 2004 (gmt 0)

10+ Year Member



This sounds like it's heading toward what I need. Now please don't hate me for this, but I don't know how to "redirect" to a different page. FWIW, I'm using perl only - no php.

When I have a form, it's simply:

<form action="prog1.pl">

When they hit the submit button, it goes to prog1.pl, which does a bunch of stuff and ultimately sends the html code to their browser. In their browser address will be [......]

From what you're saying, I gather that there is a way that prog1.pl would do all the behind-the-scenes work like verifying, entering into the database, etc., and once that's done, it forwards on to prog2.pl, which displays the page for the user. If the user hits refresh, he's just refreshing prog2.pl, right? And if I am right, um, how is that done please?

flashfan

5:12 pm on Jul 2, 2004 (gmt 0)

10+ Year Member



It's easily done in perl.

#using one cgi for multiple pages
sub build_form
{
...
%fields = GetFields(); # use param to capture fields and their values;

$value1 = (exists $fields{FIELD1} and $fields{FIELD1})? $fields{FIELD1} : '';
$formHTML .= qq{<input ... value=$value1"/>};
...

#based upon existing values to show correct page of the form
...
}

If 'Refresh' is hit, the CGI will force to 'next page', which is not finished. Do this make sense to you?