<% Response.Buffer = True Dim connStrx, Name1, City1, State1, Country1, Email1, Message1, Homepage1, rs, fh2, fhc2, fhc3
' Here we are setting the variables for connection to our database and creating an Object ' in order to to open a recordset for appending data
connStrx = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("guestbook.mdb") Set rs = CreateObject("ADODB.Recordset")
' Now that we have dimensioned variables, lets make sure we even have data to look at. ' Since this page is also the results page we need to verify there was a form submission request.
If Request.Form("Submit")="Sign-It" Then
' this checks if the form was submitted. Once we can determine this is true we can ' assign the variables we dimensioned above to hold the form data.
Name1=Request.Form("Name") City1=Request.Form("City") State1=Request.Form("State") Country1=Request.Form("Country") Message1=Request.Form("Message") HomePage1=Request.Form("Homepage") email1=Request.Form("Email")
' Now that we have filled the variables with the form data we can verify the required ' fields indeed have information. To do this we look at the length of the string data ' we aquired from the form. If the length of the data is 0 we can assume the field was ' skipped over and no information was inserted.
If len(trim(name1))=0 or len(trim(city1))=0 or len(trim(state1))=0 or len(trim(country1))=0 Then response.write "<center><h3><font color=red>Missing Required Data. Try again</font></h3>"
' You can stop here and give a link back to the form or you can let the visitor know ' exactly which fields they missed. To do that we look at each required field and ' determine if the condition is true. If it is we issue a write statement to inform ' the visitor of what fields are missing data.
if len(trim(name1))=0 then response.write "Missing Your Name<br>" else end if
if len(trim(city1))=0 then response.write "Missing your City<br>" else end if
If len(trim(State1))=0 then response.write "Missing your State or Providence<br>" else end if
If len(trim(country1))=0 then response.write "Missing your Country<br>" else end if
' Now that we have supplied the visitor with information about the missing data ' We create a link to go back to the form and finish inserting values properly.
response.write "<a href='javascript:history.back()'><h4><font color=red><b>CLICK HERE TO FINISH FORM AND RE-SUBMIT</b></font></h4></a></center>"
Else
' if the simple logic test passes an required fields contain data, ' we can submit the data to append to our table when we designed the table we included ' a date field and time field to automatically insert the current date and time so we can just ' concentrate on form data.
rs.Open "Guestbook", connStrx, 2, 2 rs.AddNew rs("Name") = Name1 rs("City") = City1 rs("State") = State1 rs("Country") = Country1 rs("Email") = Email1 rs("Message") = Message1 rs("homepage") = Homepage1 rs.Update ' Once we insert the data we close the connection and later re-open it to retreive all the data for viewing.
rs.Close response.write "<center>Thanks for signing the GuestBook<br><a href='guestbook.asp'>Click here to view your entry</a></center>"
' This is our success response. It includes a link to view the results. ' Notice the link is the same as the page we are creating End If
Else %>
|