| This is a standard (not Win-CGI) CGI script guest book example, using the VB5-CGI Objects from EazyWare. It runs On every Win 95/98/NT4.0 standard CGI capable web server, e.g. PWS, IIS, Netscape, WebSite, Xitami, Apache,...This code can be live tested at http://www.eazyware.com/vb5-cgi/index.htm. Guest book script which stores the entries in a text file. - Creates the HTML document itself, just provide a link to the .exe file. - Shows all information on one page. - Validates the entries and highlights the missing input fields without JavaScript. - Removes HTML tags from entries. - Shows the last entry On top of the list. - Shows additional information like host and used browser. The free VB5-CGI Objects TRIAL EDITION has no using time limit, but only one instance at a given time can be run. You need Visual Basic 5.0 With Service Pack 2 or 3 and a Win 95/98/NT4.0 standard CGI capable web server, e.g. PWS, IIS, Netscape, WebSite, Xitami, Apache,... Put the demoGuestBook.exe in your web server's script directory (with executable rights) and enter in your browser the URL http://127.0.0.1/scripts/demoGuestBook.exe Side Effects:None VB5-CGI Objects script example: demoGuestbook.bas Copyright 1997, 1998 EazyWare - http://www.eazyware.com/vb5-cgi Guest book script which stores the entries in a text file. - Creates the HTML document itself, just provide a link to the .exe file. - Shows all information on one page. - Validates the entries and highlights the missing input fields without JavaScript. - Removes HTML tags from entries. - Shows the last entry on top of the list. - Shows additional information like host and used browser. - Doesen't allow to save the same entry multiple times (reload button). To use the script on WIN95/NT with a Web server you need to: - Register VB5CGI.DLL and VB5HTML.DLL using RegSvr32.exe. - Copy MSVBVM50.DLL (SP2) to the %System32% or script directory. - Compile this script to an .exe (use 'Unattended Execution' in Project Properties). Remarks: - I use '+' instead of '&' to concat strings, because of better performance (type String). - The .exe file can be renamed after compilation, because the script name is retrieved dynamically. 'Windows API/Global Declarations: You need a Reference to the VB5CGI and VB5HTML object version 2.01 (VB5-CGI.DLL and VB5HTML.DLL). Option Explicit Private Const METHOD = "GET"'Method to be used, either 'GET' or 'POST' Private GuestBookFile As String 'Guest book text filename Private CGI As New VB5CGI.clsCGI'Instance the VB5CGI Object (needs VB5CGI.DLL) Private HTML As New VB5HTML.clsHTML 'Instance the VB5HTML Object (needs VB5HTML.DLL) Sub Main() Dim pos As Integer Dim msg As String With HTML GuestBookFile = CGI.GetPath + "demoGuestbook.txt"'Set the guest book file accordingly .ErrorSubText = " Please send your comments to " + _ "EazyWare" If .InitQueryString(False, 1024) Then 'Retrieve the query string (from 'GET' or 'POST' method), imit to 1024 chars 'A query string exists, validate all entries If Not .HasKeyValidStringContent("name", htmlLetterUS + htmlSpace, 3, 40) Then msg = "Please enter your name (US letters, spaces, 3 to 40 characters):" pos = 1 End If If (pos = 0) And Not .HasKeyValidEmail("email") Then msg = "Please enter your valid e-mail address:"'And End the script pos = 2 End If If (pos = 0) And Not .HasKeyValidStringLen("comment", 1, 300) Then msg = "Please enter your comment (1 to 300 characters):"'And End the script pos = 3 End If .PageBegin "VB5-CGI Objects demo: Guest Book", "#FFFFFF" If pos > 0 Then 'Validation error occured, show the form with highlighted input fields, but don't show the guest book entries .BodyHTML GetGuestbookForm(.GetKeyString("name", True), .GetKeyString("email", True), _ .GetKeyString("comment", True), pos, msg) Else 'No validation error, add the new entry to the top and show all of them msg = AddGuestBookEntry(.GetKeyString("name", True), .GetKeyString("email", True), _ .GetKeyString("comment", True)) .BodyHTML GetGuestbookForm(, , , , "Thanks " + .GetKeyString("name", True) + _ ", your entry has been added to the top!") + msg End If .PageEnd'Submit the page Else 'No query string received, show the guest book form and existing entries msg = HTML.GetFileText(GuestBookFile, False) If msg = "" Then msg = " No guest book entry yet ..." .PageBegin "VB5-CGI Objects demo: Guest Book", "#FFFFFF" .BodyHTML GetGuestbookForm() + msg .PageEnd'Submit the page End If End With End Sub 'Returns the the guestbook form as HTML and highlights an invalid input field Private Function GetGuestbookForm(Optional Name As String, Optional Email As String, _ Optional Comment As String, _ Optional ErrorPos As Integer, Optional FormTitle As String) As String Const ERROR_COLOR = "BGCOLOR=""#FF0000"" " Dim msg As String Dim namecol As String Dim emailcol As String Dim commentcol As String Select Case ErrorPos Case 1 namecol = ERROR_COLOR'Invalid name Case 2 emailcol = ERROR_COLOR 'Invalid e-mail Case 3 commentcol = ERROR_COLOR'Invalid comment End Select If FormTitle = "" Then FormTitle = "Would you like to sign the guest book?" msg = " VB5-CGI Objects demo: Guest Book" + vbCrLfmsg = msg + "CGI script: " + CGI.GetScriptName + " " + vbCrLf msg = msg + "" + FormTitle + "" + vbCrLf msg = msg + "" + vbCrLf GetGuestbookForm = msg End Function 'Adds a new entry to the guest book file and returns all guest book entries Private Function AddGuestBookEntry(Name As String, Email As String, Comment As String) As String Dim ffree As Integer Dim addmsg As String Dim oldmsg As String On Error Goto ErrorRoutine oldmsg = HTML.GetFileText(GuestBookFile, False) 'Get the guest book entries addmsg = " " + Comment + " " + vbCrLf addmsg = addmsg + "Added by: " + _ Name + " on: " If InStr(oldmsg, addmsg) Then'Check, if new entry already exists in guest book HTML.ErrorPage Name + ", you already entered the same content! This new entry _ addmsg = addmsg + oldmsg ffree = FreeFile() Open GuestBookFile For Output Lock Write As #ffree Print #ffree, addmsg 'Save it to the guest book Close #ffree AddGuestBookEntry = addmsg Exit Function ErrorRoutine: HTML.ErrorPage "File error occured, please try again! Description: " + Err.Description |
DemoGuestbook.bas |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design