Link to home
Create AccountLog in
Avatar of Malloy1446
Malloy1446

asked on

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 title
title = "Form"

'--------------------------------------------------------------------------------------------
dim ChartID
ChartID = 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 database

dim objRS, strCol, ILLID

'open recordset
'open recordset where the data from the previous page will be stored


sql = "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 email

dim strRecips
strRecips = "email@gmail.com"


While Not RSListRecipients.EOF
'Following line displays the requestor's email
	response.Write("<br/>" & RSListRecipients("SDEmail"))
	strRecips = strRecips & RSListRecipients("SDEmail") & ";"
	RSListRecipients.MoveNext
Wend

'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>&nbsp;&nbsp;Type of Request: " & request.form("ILLRequestType")

	IF request.form("ILLRequestType") = "Book" THEN
		txtBody = txtBody & "<p>&nbsp;&nbsp;Book Author: " & request.form("ILLBookAuthor")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Book Title: " & request.form("ILLBookTitle")
		txtBody = txtBody & "<br>&nbsp;&nbsp;ISBN: " & request.form("ILLBookISBN")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Book Chapter: " & request.form("ILLBookChapter")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Book Chapter Pages: " & request.form("ILLBookChapterPages")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Publisher: " & request.form("ILLBookPublisher")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Publication Date: " & request.form("ILLBookPubYear")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Edition: " & request.form("ILLBookEd")
	END IF
	
	IF request.form("ILLRequestType") = "Audiovisual" THEN
		txtBody = txtBody & "<p>&nbsp;&nbsp;Audiovisual Title: " & request.form("ILLAVTitle")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Producer: " & request.form("ILLAVProducer")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Production Year: " & request.form("ILLAVProductionYear")
	END IF
	
	IF request.form("ILLRequestType") = "Journal Article" THEN
		txtBody = txtBody & "<p>&nbsp;&nbsp;Journal Title: " & request.form("ILLJournalTitle")
		txtBody = txtBody & "<br>&nbsp;&nbsp;ISSN: " & request.form("ILLJournalISSN")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Volume: " & request.form("ILLJournalVolume")
		txtBody = txtBody & "&nbsp;&nbsp;Issue: " & request.form("ILLJournalIssue") 
		txtBody = txtBody & "&nbsp;&nbsp;Publication Date: " & request.form("ILLJournalPubDate") 
		txtBody = txtBody & "<br>&nbsp;&nbsp;PMID: " & request.form("ILLJournalPMID")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Journal Article: " & request.form("ILLJournalArticle")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Author: " & request.form("ILLJournalArticleAuthor")
		txtBody = txtBody & "<br>&nbsp;&nbsp;Page range: " & request.form("ILLJournalPages")
	END IF

		txtBody = txtBody & "<br>&nbsp;&nbsp;Not needed after: " & request.form("ILLNotNeeded")
		txtBody = txtBody & "<br>&nbsp;&nbsp;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>&nbsp;</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 If

Response.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>

Open in new window

Avatar of John_Vidmar
John_Vidmar
Flag of Canada image

Save the values in a form with hidden-fields; the submit-button (line 243) would be replaced with the following:
<form action="Eligible.asp" >
	<input type="hidden" name="ILLRequestorsFName"   value="<%=request.form("ILLRequestorsFName")%>"   />
	<input type="hidden" name="ILLRequestorsLName"   value="<%=request.form("ILLRequestorsLName")%>"   />
	<input type="hidden" name="ILLRequestorsService" value="<%=request.form("ILLRequestorsService")%>" />
	<input type="hidden" name="ILLRequestorsEmail"   value="<%=request.form("ILLRequestorsEmail")%>"   />
	<input type="hidden" name="ILLRequestorsPhone"   value="<%=request.form("ILLRequestorsPhone")%>"   />
	<input type="submit" value="Submit another request" />
</form> 

Open in new window

Avatar of Malloy1446
Malloy1446

ASKER

I tried the suggested code with just one field. It returns to the Eligible.asp page with the following URL:

Eligible.asp?ILLRequestorsFName=bbb

Although the field is NOT filled in.
do you have code on your form fields to read in these values? I would also change the form's method to POST:

eligible2.asp - line 243
<form action="Eligible.asp" method="POST" >
	<input type="hidden" name="ILLRequestorsFName"   value="<%=request.form("ILLRequestorsFName")%>"   />
	<input type="hidden" name="ILLRequestorsLName"   value="<%=request.form("ILLRequestorsLName")%>"   />
	<input type="hidden" name="ILLRequestorsService" value="<%=request.form("ILLRequestorsService")%>" />
	<input type="hidden" name="ILLRequestorsEmail"   value="<%=request.form("ILLRequestorsEmail")%>"   />
	<input type="hidden" name="ILLRequestorsPhone"   value="<%=request.form("ILLRequestorsPhone")%>"   />
	<input type="submit" value="Submit another request" />
</form> 

Open in new window


eligible.asp - whatever line your field is on:
<input type="text" name="ILLRequestorsFName" value="<%=Request("ILLRequestorsFName")%>" />

Open in new window

On eligible.asp I added the value.
On eligible2.asp my form code

<form action="Eligible.asp" method="POST">
	<input type="hidden" name="ILLRequestorsFName" value="request.form('ILLRequestorsFName')" />
	<input type="submit" value="Submit another request" />
</form>

Open in new window


When I click Submit, Eligible.asp displays request.form('ILLRequestorsFName') on the form
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Another options is in your insert code you are grabbing the an the identity id for tblILLRequests on line 60
ILLID = objRS(0).

Open in new window

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.