Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 programmatically populate a form
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

govictor
Starting Member

USA
2 Posts

Posted - 02 June 2011 :  18:04:42  Show Profile  Reply with Quote
I was wondering anyone would be able to point me to the right direction on where I can find information for a web form I am working on. I would like the form to auto populate with name, email, phone number etc. once I enter an email address. I would also like the to insert the new requestor information in the table if they are not found in the table. The current form was created using asp. I appreciate your help.

victor

Doug G
Support Moderator

USA
6493 Posts

Posted - 03 June 2011 :  01:13:27  Show Profile  Reply with Quote
Basically you have your asp code add the appropriate Value attributes to each form element in the html stream.

======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

govictor
Starting Member

USA
2 Posts

Posted - 03 June 2011 :  10:20:57  Show Profile  Reply with Quote
Hello Doug,
Thanks for your response. I am new to asp. would you please be able to give me an example. This is the code I have been able to come up with but I do not know what I am missing:

<%
Dim EMAIL

EMAIL = nz(DLookup("[EMAIL]","REQUESTOR","[EMAIL]=" & Me!EMAIL),0)
If EMAIL = 0 Then
Msgbox "This requestor does not exist in table Requestor"



<% Private Function RecordExists() As Boolean
Dim WebProjects.mdb Database
Dim MM_editCmd As DAO.Recordset
Dim MM_editCmd As String

'Check that all the relevent controls meet the criteria
If Nz(Me.FIRST_NAME, 0) > 0 AND Len(Nz(Me.LAST_NAME, "")) > 0 AND Len(Nz(Me.PHONE_NUMBER, "")) > 0 AND Len(Nz(Me.DEPARTMENT, "")) > 0 AND Len(Nz(Me.EMAIL, "")) > 0
Then
MM_editCmd.CommandText = SELECT (FIRST_NAME, LAST_NAME, PHONE_NUMBER, DEPARTMENT, EMAIL) FROM WEB_REQUESTS WHERE )
Me.FIRST_NAME & '
Me.lAST_NAME & '
Me.PHONE_NUMBER & '
Me.DEPARTMENT & """"
Me.EMAIL & """"

%>


I appreciate your help.
Victor



quote:
Originally posted by Doug G

Basically you have your asp code add the appropriate Value attributes to each form element in the html stream.

Go to Top of Page

Carefree
Advanced Member

Philippines
4212 Posts

Posted - 26 June 2011 :  06:41:09  Show Profile  Reply with Quote
Here's an example. Note the bits in red. The first table/form simply requests the Email address & submits the form to check it. If it's found, the second table will be populated with the fields from the database; otherwise the error message will be displayed. If the second form is submitted and the EMail account exists, the information in the database will be updated, if the EMail account does not exist, the information will be added to the database.


<%
<%
Session.LCID = 1033
Response.CodePage = 65001
Response.CharSet = "utf-8"
Response.Buffer = True
Set my_Conn = Server.CreateObject("ADODB.Connection")
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\webrequests.mdb"
my_Conn.Open strConnString
Dim EMail
If Request.Form("HiddenField")="InUse" Then
	strSql = "SELECT * FROM WEB_REQUESTS WHERE EMAIL='" & Request.Form("EMail") & "'"
	Set rs=my_Conn.Execute(strSql)
	If not rs.EOF Then
		strLast=rs("Last_Name")
		strFirst=rs("First_Name")
		strPhone=rs("Phone_Number")
		strDept=rs("Department")
		strEmail=rs("EMail")
		rs.Close
	Else
		Response.Write 	"<table width=""500px;"" align=""center"" border=""1"" style=""border-collapse:collapse;"" cellpadding=""0"" cellspacing=""0"" bgColor=""#FF3333"">" & vbNewLine & _
			"	<tr valign=""middle"">" & vbNewLine & _
			"		<td align=""center"" width=""100%"">" & vbNewLine & _
			"			<font face=""arial unicode ms"" size=""4"" color=""#000066""><b>Requestor does not exist.</b>" & vbNewLine & _
			"			</font>" & vbNewLine & _
			"		</td>" & vbNewLine & _
			"	</tr>" & vbNewLine & _
			"</table>" & vbNewLine & _
			"<meta http-equiv=""Refresh"" content=""10; URL=thispage.asp"">"
		Response.End
	End If
	Set rs=Nothing
ElseIf Request.Form("HiddenField")="NotInUse" Then
	strSql = "SELECT * FROM WEB_REQUESTS WHERE EMAIL='" & Request.Form("EMail") & "'"
	Set rs=my_Conn.Execute(strSql)
	If not rs.EOF Then
		rs.Close
		strSql = "UPDATE WEB_REQUESTS SET Last_Name='" & Request.Form("LName") & "', First_Name='" & Request.Form("FName") & "', Phone_Number='" & Request.Form("Phone") & "', Department='" & Request.Form("Dept") & "' WHERE EMail='" & Request.Form("EMail") & "'"
		my_Conn.Execute(strSql)
	Else
		strSql = "INSERT INTO WEB_REQUESTS (Last_Name, First_Name, Phone_Number, Department, EMail) VALUES ('" & Request.Form("LName") & "', '" & Request.Form("FName") & "', '" & Request.Form("Phone") & "', '" & Request.Form("Dept") & "', '" & Request.Form("EMail") & "')"
		my_Conn.Execute(strSql)
	End If
	Set rs=Nothing
	Response.Redirect "thispage.asp"
End If
Response.Write	"<form action=""thispage.asp"" method=""post"">" & vbNewLine & _
	"	<input type=""hidden"" name=""HiddenField"" value=""InUse"">" & vbNewLine & _
	"	<table width=""500px;"" align=""center"" border=""1"" style=""border-collapse:collapse;"" cellpadding=""0"" cellspacing=""0"" bgColor=""#FF3333"">" & vbNewLine & _
	"		<tr valign=""middle"">" & vbNewLine & _
	"			<td align=""center"" width=""100%"">" & vbNewLine & _
	"				<table align=""center"" width=""100%"" cellpadding=""2"" border=""1"" style=""border-collapse:collapse;"">" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""center"" colspan=""2"" width=""100%"" bgColor=""#0066FF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""4"" color=""#000066""><b>Requestor</b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""right"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""2"" color=""#440000""><b>      Email: </b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"						<td align=""left"" width=""50%"" bgColor=""#FFFF9C"">" & vbNewLine & _
	"							<input type=""text"" name=""EMAIL"" value=""" & strEmail & """ size=""50"" maxlength=""75"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""center"" colspan=""2"" width=""100%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<input type=""submit"" value=""Submit"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"				</table>" & vbNewLine & _
	"			</td>" & vbNewLine & _
	"		</tr>" & vbNewLine & _
	"	</table>" & vbNewLine & _
	"</form><br>" & vbNewLine & _
	"<form action=""thispage.asp"" method=""post"">" & vbNewLine & _
	"	<input type=""hidden"" name=""HiddenField"" value=""NotInUse"">" & vbNewLine & _
	"	<table width=""500px;"" align=""center"" border=""1"" style=""border-collapse:collapse;"" cellpadding=""0"" cellspacing=""0"" bgColor=""#FF3333"">" & vbNewLine & _
	"		<tr valign=""middle"">" & vbNewLine & _
	"			<td align=""center"" width=""100%"">" & vbNewLine & _
	"				<table align=""center"" width=""100%"" border=""1"" cellpadding=""2"" style=""border-collapse:collapse;"">" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""center"" colspan=""2"" width=""100%"" bgColor=""#0066FF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""4"" color=""#000066""><b>Identification</b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""right"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""2"" color=""#440000""><b>Last Name: </b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"						<td align=""left"" width=""50%"" bgColor=""#FFFF9C"">" & vbNewLine & _
	"							<input type=""text"" name=""LName"" value=""" & strLast & """ size=""50"" maxlength=""75"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""right"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""2"" color=""#440000""><b>First Name: </b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"						<td align=""left"" width=""50%"" bgColor=""#FFFF9C"">" & vbNewLine & _
	"							<input type=""text"" name=""FName"" value=""" & strFirst & """ size=""50"" maxlength=""75"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""right"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""2"" color=""#440000""><b>Phone: </b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"						<td align=""left"" width=""50%"" bgColor=""#FFFF9C"">" & vbNewLine & _
	"							<input type=""text"" name=""Phone"" value=""" & strPhone & """ size=""50"" maxlength=""75"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""right"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""2"" color=""#440000""><b>Department: </b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"						<td align=""left"" width=""50%"" bgColor=""#FFFF9C"">" & vbNewLine & _
	"							<input type=""text"" name=""Dept"" value=""" & strDept & """ size=""50"" maxlength=""75"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""right"" width=""50%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<font face=""arial unicode ms"" size=""2"" color=""#440000""><b>EMail: </b>" & vbNewLine & _
	"							</font>" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"						<td align=""left"" width=""50%"" bgColor=""#FFFF9C"">" & vbNewLine & _
	"							<input type=""text"" name=""EMail"" value=""" & strEMail & """ size=""50"" maxlength=""75"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"					<tr valign=""middle"">" & vbNewLine & _
	"						<td align=""center"" colspan=""2"" width=""100%"" bgColor=""#FFFFFF"">" & vbNewLine & _
	"							<input type=""submit"" value=""Submit"">" & vbNewLine & _
	"						</td>" & vbNewLine & _
	"					</tr>" & vbNewLine & _
	"				</table>" & vbNewLine & _
	"			</td>" & vbNewLine & _
	"		</tr>" & vbNewLine & _
	"	</table>" & vbNewLine & _
	"</form>" & vbNewLine
%>

Edited by - Carefree on 26 June 2011 07:11:15
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000 Version 3.4.07