Populate form with previously submitted information
I have a form which asks for some personal information. Then an option to select a type with additional information to enter. Once the form is complete, the user submits the data and it is entered in an MSDatabase and sent via email. On the submit page, I want to include an option to submit another request (line 243) and automatically include the users personal information. There are 5 fields I want to include (ILLRequestorsFName, ILLRequestorsLName, ILLRequestorsService, ILLRequestorsEmail, ILLRequestorsPhone).
The form is Eligible.asp.
The confirmation page is Eligible2.asp
I am including the code for Eligible2.asp.
<%@LANGUAGE="VBSCRIPT"%><!-- #Include Virtual="CodeReuse/ConnTesting.inc" --><%'response.Write("chartID: " & session("ChartID"))'response.End()%><%dim titletitle = "Form"'--------------------------------------------------------------------------------------------dim ChartIDChartID = session("ChartID")'--------------------------------------------------------------------------------------------dim sql2, RSListRecipients sql2= "SELECT SDEmail FROM tblStaffDirectory WHERE ChartID=" & ChartID & " and ILLContact='Y'"'response.Write("sql2: " & sql2)'response.End() set RSListRecipients = objConn.Execute(sql2)'--------------------------------------------------------------------------------------------'insert the information from the previous page into the databasedim objRS, strCol, ILLID'open recordset'open recordset where the data from the previous page will be storedsql = "Select * FROM tblILLRequests WHERE (ILLID = " & Request.form("ILLID") & ")" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open "tblILLRequests", objConn, adOpenStatic, adLockOptimistic, adCmdTable 'Crete new record. objRS.AddNew 'Input data in tblILLRequests. For each strCol in Request.Form If Len(Request(strCol)) > 0 then objRS(strCol) = Request.Form(strCol) End If Next'Write the record to the database.objRS.Update'Get the unique ID of the record we just created. 'We'll use this ID in the other tables, and will pass it to subsequent pages in a hidden form field.Set objRS = objConn.Execute( "SELECT @@IDENTITY" )ILLID = objRS(0)objRS.close'---------------------------------------------- Mail function ---------------------------------------'Following is code to send emaildim strRecipsstrRecips = "email@gmail.com"While Not RSListRecipients.EOF'Following line displays the requestor's email response.Write("<br/>" & RSListRecipients("SDEmail")) strRecips = strRecips & RSListRecipients("SDEmail") & ";" RSListRecipients.MoveNextWend'following line displays WHO the message is sent to'Response.Write("<br/>" & strRecips)txtTo = strRecips'---------------------------------------------- Body of email ---------------------------------------txtFrom = request.form("ILLRequestorsEmail")txtSub = "ILL Online Request"txtBody = "Requestor's Name: " & request.form("ILLRequestorsFName") & " " & request.form("ILLRequestorsLName")txtBody = txtBody & "<br>Service: " & request.form("ILLRequestorsService")txtBody = txtBody & "<br>Email: " & request.form("ILLRequestorsEmail")txtBody = txtBody & "<br>Phone: " & request.form("ILLRequestorsPhone") txtBody = txtBody & "<p> Type of Request: " & request.form("ILLRequestType") IF request.form("ILLRequestType") = "Book" THEN txtBody = txtBody & "<p> Book Author: " & request.form("ILLBookAuthor") txtBody = txtBody & "<br> Book Title: " & request.form("ILLBookTitle") txtBody = txtBody & "<br> ISBN: " & request.form("ILLBookISBN") txtBody = txtBody & "<br> Book Chapter: " & request.form("ILLBookChapter") txtBody = txtBody & "<br> Book Chapter Pages: " & request.form("ILLBookChapterPages") txtBody = txtBody & "<br> Publisher: " & request.form("ILLBookPublisher") txtBody = txtBody & "<br> Publication Date: " & request.form("ILLBookPubYear") txtBody = txtBody & "<br> Edition: " & request.form("ILLBookEd") END IF IF request.form("ILLRequestType") = "Audiovisual" THEN txtBody = txtBody & "<p> Audiovisual Title: " & request.form("ILLAVTitle") txtBody = txtBody & "<br> Producer: " & request.form("ILLAVProducer") txtBody = txtBody & "<br> Production Year: " & request.form("ILLAVProductionYear") END IF IF request.form("ILLRequestType") = "Journal Article" THEN txtBody = txtBody & "<p> Journal Title: " & request.form("ILLJournalTitle") txtBody = txtBody & "<br> ISSN: " & request.form("ILLJournalISSN") txtBody = txtBody & "<br> Volume: " & request.form("ILLJournalVolume") txtBody = txtBody & " Issue: " & request.form("ILLJournalIssue") txtBody = txtBody & " Publication Date: " & request.form("ILLJournalPubDate") txtBody = txtBody & "<br> PMID: " & request.form("ILLJournalPMID") txtBody = txtBody & "<br> Journal Article: " & request.form("ILLJournalArticle") txtBody = txtBody & "<br> Author: " & request.form("ILLJournalArticleAuthor") txtBody = txtBody & "<br> Page range: " & request.form("ILLJournalPages") END IF txtBody = txtBody & "<br> Not needed after: " & request.form("ILLNotNeeded") txtBody = txtBody & "<br> Additional Info: " & request.form("ILLInfo")%> <!-- #INCLUDE VIRTUAL="CodeReuse/Mailer2.asp" --><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title><%=title%></title><link rel=stylesheet type="text/css" href="CodeReuse/style.css"></head><body><h2><%=title%> - Request Submitted</h2><p> </p><hr><div id="LrgPrt"><p align="center"> Thank you for using the <b><i>Online Interlibrary Loan form</i></b>. <br>Your request has been sent to your facility library staff.<hr><%Response.Write "The following data has been submitted<p>"Response.Write "<blockquote>"Response.Write "<b>Name: </b>" & request.form("ILLRequestorsFName") & " " & request.form("ILLRequestorsLName")If LEN(Request.form("ILLRequestorsService"))>0 THEN Response.Write "<br><b>Service: </b>" & request.form("ILLRequestorsService")End IfResponse.Write "<br><b>Email: </b>" & request.form("ILLRequestorsEmail")If LEN(Request.form("ILLRequestorsPhone"))>0 THEN Response.Write "<br><b>Phone: </b>" & request.form("ILLRequestorsPhone")End If'---------------------------- Verification of AV Request ----------------------------IF request.form("ILLRequestType") = "Audiovisual" THEN Response.Write "<blockquote><b>Audiovisual Request</b><br>" Response.Write "<br><b>Audiovisual Title: </b>" & request.form("ILLAVTitle") Response.Write "<br><b>Producer: </b>" & request.form("ILLAVProducer") Response.Write "<br><b>Production Year: </b>" & request.form("ILLAVProductionYear") Response.Write "<br><b>Not needed after: </b>" & request.form("ILLNotNeeded") Response.Write "<br><b>Additional Info: </b>" & request.form("ILLInfo") Response.Write "</blockquote>"END IF'-------------------------- Verification of Journal Request --------------------------IF request.form("ILLRequestType") = "Journal Article" THEN Response.Write "<blockquote><b>Journal Article Request</b><br>" Response.Write "<br><b>Journal Title: " & request.form("ILLJournalTitle") Response.Write "<br><b>ISSN: " & request.form("ILLJournalISSN") Response.Write "<br><b>Volume: " & request.form("ILLJournalVolume") Response.Write "<br><b>Issue: " & request.form("ILLJournalIssue") Response.Write "<br><b>Publication Date: " & request.form("ILLJournalPubDate") Response.Write "<br><b>PMID: " & request.form("ILLJournalPMID") Response.Write "<br><b>Journal Article: " & request.form("ILLJournalArticle") Response.Write "<br><b>Author: " & request.form("ILLJournalArticleAuthor") Response.Write "<br><b>Page range: " & request.form("ILLJournalPages") Response.Write "<br><b>Not needed after: </b>" & request.form("ILLNotNeeded") Response.Write "<br><b>Additional Info: </b>" & request.form("ILLInfo") Response.Write "</blockquote>"END IF'-------------------------- Verification of Book Request --------------------------IF request.form("ILLRequestType") = "Book" THEN Response.Write "<blockquote><b>Journal Article Request</b><br>" Response.Write "<br><b>Book Author: " & request.form("ILLBookAuthor") Response.Write "<br><b>Book Title: " & request.form("ILLBookTitle") Response.Write "<br><b>ISBN: " & request.form("ILLBookISBN") Response.Write "<br><b>Book Chapter: " & request.form("ILLBookChapter") Response.Write "<br><b>Book Chapter Pages: " & request.form("ILLBookChapterPages") Response.Write "<br><b>Publisher: " & request.form("ILLBookPublisher") Response.Write "<br><b>Publication Date: " & request.form("ILLBookPubYear") Response.Write "<br><b>Edition: " & request.form("ILLBookEd") Response.Write "<br><b>Not needed after: </b>" & request.form("ILLNotNeeded") Response.Write "<br><b>Additional Info: </b>" & request.form("ILLInfo") Response.Write "</blockquote>"END IF%>Submit another request<p></div></body></html>
You could also submit the field ILLID as a hidden field, session variable or cookie. Then in your processing page, look up the data you need from tblILLRequests and copy it over.
One advantage to this method is you will know for sure the personal data is not altered. Even if you use a hidden field, it is still subject to change and as a rule you shouldn't trust input data.
Still another option is to simply add a field "OriginalRquestID" and make the default value in your db zero. When you submit the 2nd or any subsequent request, use the field ILLID to populate. Then you can always grab the personal information from the original request. As a side benefit, you track how many related requests are being made.
Open in new window