Free input form all done from one Page using Sub Procedures

 

Contributed by
Rating: 2 stars2 stars2 stars2 stars2 stars / 3
October 11, 1999
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

<h2>Please Enter contact information in the form below so we may contact you about advertising.</h2>
<table border="1" width="100%">
<tr>
<td width="18%">Name:</td>
<td width="82%"><input type="text" name="name" size="40"></td>
</tr>
<tr>
<td width="18%">Email Address:</td>
<td width="82%"><input type="text" name="emailaddress" size="40"></td>
</tr>
<tr>
<td width="18%">Phone Number:</td>
<td width="82%"><input type="text" name="phonenumber" size="40"></td>
</tr>
<tr>
<td width="18%">Comments</td>
<td width="82%">&nbsp;</td>
</tr>
<tr>
<td colspan="2" width="100%"><textarea rows="6" name="comments" cols="58"></textarea></td>
</tr>
</table>
<p>&nbsp;</p>
<p><input type="submit" value="Submit" name="btnSubmit"><input type="reset" value="Reset"
name="B2"></p>
</form>
</BODY>

</html>

<% End Sub %>

3 of 3 subs that is used in this example  This procedure does the server-side code to insert a record and send an email.  Then it redirects back to the form with one request.querystring variable to notify the Thank you page to be displayed.


<% Sub DoRecords() %>

'Note that I'm using an include file for my connection string, sense all server-side processing that needs a database connection is inside this sub that is where I place the connection string.  You could easily put a DSN Entry, DSN-Less entry in here too.


<!--#include file="conn.asp"-->
<%
dim strconn
dim conn
dim rs

set conn = server.createobject("adodb.connection")
conn.open strconn
set rs = server.createobject("adodb.recordset")
rs.open "PutYourTableNameHere", conn, 3, 3
rs.addnew
rs("name") = request("name")
rs("emailaddress") = request("emailaddress")
rs("phonenumber") = request("phonenumber")
rs("comments") = request("comments")
rs("DateSubmitted") = date()
rs.update
rs.close
set rs = nothing
conn.close
set conn = nothing

'Builds the body of the Message
strBody = "A request for some info about your site" & chr(10) & chr(10) 
strBody = strBody & "Name: " & request("Name") & chr(10)
strBody = strBody & "EmailAddress: " & request("Emailaddress") & chr(10)
strBody = strBody & "PhoneNumber: " & request("PhoneNumber") & chr(10)
strBody = strBody & "Comments: " & chr(10) & request("comments")


'Mails a copy of this request to the someone

set objNewMail = server.CreateObject("CDONTS.NewMail")
objNewMail.From = "ASPFree.com"
objNewMail.To = "someone@aspfree.com"
objNewMail.BCC = "someone@aspfree.com"
objNewMail.Subject = "A Simple form to collect info"
objNewMail.Body = strBody
objNewMail.Send
set objNewMail = Nothing
response.redirect "ads.asp?strMessage=Thanks"
End Sub

%>
<% 

This is where the real logic is done.

'This If statement displays the Intro Page
If request("btnSubmit") = "" and request("strMessage") = "" Then
call IntroPage()
End If

This if calls the DoRecords() Sub to process the form values
If request("btnSubmit") = "Submit" Then
call DoRecords()
End If

This if processes the Thank you page after the form was submitted
if request("strMessage") <> "" Then
call Thanks()
End If

%>

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials