clear the post in a form how?

J

Jim S.

I have a form that submits the content via a POST (not get) method, but the
problem is , i want to clear the post from the browser after every
submission, since the problem is, if the user refreshes the browser, it
REsubmits the form/produc. so how can i do that?
 
J

Jim Buyens

-----Original Message-----
I have a form that submits the content via a POST (not
get) method, but the problem is , i want to clear the
post from the browser after every submission, since the
problem is, if the user refreshes the browser, it
REsubmits the form/produc. so how can i do that?

This is relatively dificult, even if you're doing your
own ASP or ASP.NET programming.

Generally, you must assign some some sort of sequence
number when you first display the form. You store this
sequence number in a hidden form field or in the ASP.NET
ViewState object. You also store it in the Session object
or in your database with a status code that means Pending.

When you successfully process the submission, you update
the status code to something that means Complete.

If the Web visitor then clicks Back and reclicks Submit,
the visitor will resubmit the same sequence number. Your
code can detects that the status is already Complete and
bounce the attempt.

Jim Buyens
Microsoft FrontPage MVP
(e-mail address removed)
http://www.interlacken.com
Author of:
*------------------------------------------------------*
|\----------------------------------------------------/|
|| Microsoft Office FrontPage 2003 Inside Out ||
|| Microsoft FrontPage Version 2002 Inside Out ||
|| Web Database Development Step by Step .NET Edition ||
|| Troubleshooting Microsoft FrontPage 2002 ||
|| Faster Smarter Beginning Programming ||
|| (All from Microsoft Press) ||
|/----------------------------------------------------\|
*------------------------------------------------------*
 
J

Jim S.

I know i may be asking too much, but can you elaborate on that?
or give an example of one field ?

It has been suggested to make two file, 1 that is a just the form collecting
the data, and 2nd to post the data to the database and then redirect back to
the form, do u think that will work?

thanks
Jim
 
J

Jim Buyens

Jim S. said:
I know i may be asking too much, but can you elaborate on that?
or give an example of one field ?

OK, but I'm just typing this cold. It's not debugged.

I'm going to assume that you have an Access database named
fpdb/mydatabase.mdb, with a table named mytable having these
three fields:

seqnum Autonumber, Primary Key
status Integer
visname String

This is ASP code:

<%
option explicit
%>
<html>
<body>
<%
dim seqnum
dim errmsg
dim strDb
dim conDb
dim rsDb

seqnum = request.form("seqnum") ' recycle sequence number (default)

strDb = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & server.mappath("fpdb/mydatabase.mdb")
Set conDb = Server.CreateObject("ADODB.Connection")
conDb.open strDb ' open connecttion to database
set rsDb = server.createobject("ADODB.Recordset")

if request.form("btnSub") = "" then ' btnSub is name of Submit button
InitializeForm
else
ProcessForm
end if

conDb.close
' ----------
Sub InitializeForm
dim sql
sql = "SELECT * FROM mytable where 1=0"
rsDb.Open sql, rsDb ' retrieve table structure but no records
rsDb.AddNew
rsDb("status") = 1 ' Set status to mean "not processed"
rsDb("visname") = ""
rsDb.Update
seqnum = rsDb("seqnum") ' get autonumber field from database
rsDb.close
End Sub
' ----------
Sub ProcessForm
dim sql
dim tmpseq
dim intseq
tmpseq = request.form("seqnum")
if not isnumeric(tmpseq) then
errmsg = "Invalid transaction sequence number."
exit sub
end if
intseq = cint(tempseq)
if intseq < 1 then
errmsg = "Invalid transaction sequence number."
exit sub
end if
sql = "SELECT * FROM mytable WHERE seqnum = " & intseq & " "
rsDb.Open sql, rsDb ' retrieve database record for assigned seq num
if rsDb.eof then
errmstg = "Transaction sequence number not found."
rsDb.close
exit sub
endif
if rsDb("Status") <> 1 then
errmsg = "Duplicate submission"
rsDb.Close
exit sub
end if
rsDb("status") = 2 ' Set status to mean "processed"
rsDb("visname") = request.form("txtName")
rsDb.Update
rsDb.Close
End Sub
' ----------
%>
<form method="POST">
<input type="hidden" name="seqnum" value="<%=seqnum%>">
<p><input type="text" name="txtName"
value="<%=request.form("txtName")%>"></p>
<p><input type="submit" name="btnSub" value="Submit"></p>
<p><%=errmsg%></p>
</form>
</body>
It has been suggested to make two file, 1 that is a just the form collecting
the data, and 2nd to post the data to the database and then redirect back to
the form, do u think that will work?

No. What to keep the visitor from pressing Submit again?

Jim Buyens
Microsoft FrontPage MVP
(e-mail address removed)
http://www.interlacken.com
Author of:
*------------------------------------------------------*
|\----------------------------------------------------/|
|| Microsoft Office FrontPage 2003 Inside Out ||
|| Microsoft FrontPage Version 2002 Inside Out ||
|| Web Database Development Step by Step .NET Edition ||
|| Troubleshooting Microsoft FrontPage 2002 ||
|| Faster Smarter Beginning Programming ||
|| (All from Microsoft Press) ||
|/----------------------------------------------------\|
*------------------------------------------------------*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top