Forms are a common way to collect data on websites. A form can be made up of a number of controls; it is the input controls are used to collect user input. Once a user fills out a form there something is usually done with the data. I often save the information to a database. Instead of scripting out and insert statement you can easily pass
‘loop’ through each of the field values and build a statement. This would assume the field names in the database table match those of the input field names on the form.
<%
STR_SQL= "INSERT INTO data ("
STR_VALUES = "VALUES ('"
For each inputField in Request.Form
STR_SQL = STR_SQL & inputField & ", "
For each inputValue in Request.Form(inputField)
STR_VALUES = STR_VALUES & inputValue & "', '"
Next
Next
STR_SQL = STR_SQL & "REMOTE_ADDR, Date_Time) "
STR_VALUES = STR_VALUES & Request.ServerVariables("REMOTE_ADDR") & "', '" & Now() & "')"
STR_SQL= STR_SQL & STR_VALUES
‘DataConn is an existind data connection and post_RS is a recordset
Set post_RS = DataConn.Execute(STR_SQL)
%>
You could also list the information on the POST page:
<%
For each inputField in Request.Form
For each inputValue in Request.Form(inputField)
Response.write(inputField & “: “ & inputValue)
Next
Next
%>
Labels: ASP, Code