Click here to Skip to main content
15,867,141 members
Articles / Programming Languages / ASP
Article

A simple feedback form in ASP 2

Rate me:
Please Sign up or sign in to vote.
3.07/5 (15 votes)
21 Jan 20043 min read 99K   2.4K   24   4
A simple ASP feedback form with a little extra features like client's IP, browser info etc.

How it looks!

Screenshot

Introduction

This is the second version of the other feedback form I submitted. I am resubmitting it because the bugs in the older version and the updating procedure takes a hell lot of time, and also it should be noted that I have become modest now (see article's title!).

This is my second contribution to CodeProject so don't be angry with me if you think that this code is below you! I have been working on this during my school vacations (took me 32 minutes for building and debugging this on Jan 12, 2004). This is a simple feedback form which allows your website's users to send you feedback directly to your email ID. And to prevent spamming of your inbox, it has been configured so that each user can give feedback to you only once in a week (cookies)! It even mails their PC info (IP, Browser Info), the time it was posted, and the number of times you have received feedback! The form disables right click on the page without any prompt, and also you can bookmark CodeProject and set it as your homepage! All this is in the source files!

Background

If you have basic knowledge about cookies and CDONTS, then this tutorial is as easy as a pie! Even if you don't know anything about cookies and CDONTS, you can just download the companion ZIP containing the source files, change the email address to your own in a text editor like Notepad, and upload it into your web server which supports ASP and CDONTS, to watch the magic!

The code

Here's the code for checking whether the user has already given you feedback in the past week:

VBScript
strfeed = Request.Cookies("Feed")("Yes")
IF (Len(strfeed) > 0) then
    Response.Write "<font color=red><b>You have already" _
             " given us feedback! You can give it again only " _
             "after a week!</b></font>"
    Response.Redirect "Index.asp"
End IF

Here's the code for requesting the form content:

VBScript
strnam = Trim(Request.Form("name"))
stremail = Trim(request.form("mail")) 
strcom = Trim(request.form("com")) 
strcom = Trim(request.form("sug"))

In the above code, the form elements are:

  1. name - The name of the user (textbox)
  2. mail - The Email ID of the user (textbox)
  3. com - Comments from the user (textarea)
  4. sug - Suggestions from the user (textarea)

Here's the code for checking if the form fields are filled or not, and submitting the form if yes:

VBScript
if (strnam <> "" and stremail <> "" and strcom <> "" _
           and strsug <> "")then
    dim newmail, strfeed, ipadd, brow, now, msgbody, date, _
                 strnam, stremail, strcom, strsug
    num = application(num)
    ipadd = Request.ServerVariables("REMOTE_ADDR")
    brow = Request.ServerVariables("HTTP_USER_AGENT")
    date = time

    msgbody = "Suggestions: " & strsug & "Comments: " & strcom & _
              vbcrlf & "PC info:" & "IP:" & ipadd & "Browser: " & brow & _
              "Time:" & date & "Hits:" & num &"times!")
    Set Newmail = server.CreateObject ("cdonts.newmail")
    Newmail.From = stremail
    Newmail.To = "someone@somewhere.com"
    Newmail.Subject = "Feedback From:" & strnam
    Newmail.Body = msgbody
    Newmail.Send
    Set Newmail = Nothing

Analysis: This code will retrieve the form fields and mail them with the IP address, browser info and time signed, to the email address 'someone@somewhere.com'! Before this code works, you need to add the following code declarations so as to enable counting the number of hits:

VBScript
Dim Num
Num = Request.Servervariables("SCRIPT_NAME")  
Application.Lock
IF isEmpty(Application(Num)) Then 
    Application(Num)=0 
END IF
Application(Num) = Application(Num)+1 
Application.Unlock

Here's the code for setting a cookie that expires after a week:

VBScript
Response.Cookies("Feed")("Yes") = "yes"
Response.Cookies("Feed").Expires = DateAdd("d",7,Now()) 
Response.Redirect "index.asp"

Analysis: Here we are setting the value yes to the cookie 'Feed' which when checked by the first bit of code will redirect the page to 'index.asp' if the value is greater than 0, i.e. (Len(strfeed)>0). After setting the cookies, the page will automatically be redirected towards 'index.asp'.

As a bonus, I am including the code for disabling right-click on an ASP page without even a prompt! Add this code into your body section! Here's the code:

JavaScript
<script language="JavaScript">
   <!--
   var message="";
   function clickIE() {if (document.all) {(message);return false;}}
   function clickNS(e){
     if (document.layers||(document.getElementById&&!document.all)) {
       if (e.which==2||e.which==3) {(message);return false;}}}
     if (document.layers){
       document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
     }
     else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
     document.oncontextmenu=new Function("return false")
</script>

Go here for an ever lasting sample!

Note: Change the email (someone@somewhere.com) address to the address where you prefer to receive the feedback, in a text editor like Notepad, and upload it into your web server which supports ASP and CDONTS, to watch the magic!

Please rate it if you do like it! Comments and suggestions are also welcome!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
Ageing considerably (16) and towering at 6 foot 2, I happen to be the one of the most eligible nerds around (for ro***ce). While I posses a sarcastic sense of humor, I tend to be a little too pessimistic sometimes.
When I'm not studyin', I strap on my back-pack and go in search of woman-eating tigers.My accomplishments include skiing down Mt. Everest, hunting (as mentioned earlier), swimming naked across the english channel during winter, writing Eminem's lyrics,advising Bush on taking critisim.
I also take pride in hac***g.

Comments and Discussions

 
QuestionI am getting internal server error on button click Pin
punithws29-Aug-11 17:58
punithws29-Aug-11 17:58 
GeneralLots of little issues with code Pin
FBPettis13-Oct-06 9:44
FBPettis13-Oct-06 9:44 
GeneralRe: Lots of little issues with code Pin
asfahaan25-May-07 7:17
asfahaan25-May-07 7:17 
GeneralFunctions declared as variables Pin
FBPettis6-Oct-06 5:26
FBPettis6-Oct-06 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.