Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Small guestbook problem

Status
Not open for further replies.

Huitzilopochtli

Programmer
Feb 18, 2002
81
DE
Hello

This is a guestbook and the idea behind the code which I've pasted below is that if the person wanting to write something in the guestbook leaves off his name, or EMail address, etc, this page reminds him to go back to complete
the details.


Unfortunately, the "Please click here to type in your Email address" appears even when the visitor HAS filled in the e.mail details, and if the visitor forgets, say, to type a message (or whatever), he gets a page saying:

"Please click here to type in your message""Please click here to type in your Email address" in other words, the site visitor gets BOTH messages. How can I ensure that the
"Please click here to type in your Email" doesn't appear on every page, and how can I ensure that only those messages which are appropriate appear, so that if a visitor does forget to type his name he will get:

"Please click here to type in your name" (and not BOTH messages)??

Grateful thanks.

The code is:

<%@ Language=VBScript %>
<%option explicit%>
<!--#include file=&quot;Connection.asp&quot;-->
<HTML>
<HEAD>

<style type=&quot;text/css&quot;>
a:link {color:#191970;}
a:visited {color:#191970;}
a:active {color:#191970;}
</style>

</HEAD>

<BODY>
<center>

<%
dim objRS, strSQL
dim strName, strSubject, strMessage, strEmail, strDate, strTime

strSQL = &quot;SELECT * FROM Forum&quot;
set objRS = server.CreateObject(&quot;ADODB.RecordSet&quot;)
objRS.Open strSQL, objConn,1,2

strName = Request.Form(&quot;txtName&quot;)
strSubject = Request.Form (&quot;txtSubject&quot;)
strMessage = Request.Form (&quot;txtMessage&quot;)
strEmail = Request.Form(&quot;txtEmail&quot;)
strDate = (Date)
strTime = (Time)


strMessage = Replace(strMessage,chr(10),&quot;<BR>&quot;)


if strName = &quot;&quot; OR strMessage = &quot;&quot; OR strSubject = &quot;&quot; OR strEmail = &quot;&quot; then

if strName = &quot;&quot; then

Response.Write (&quot;<font face='verdana' size='2' color='navy'>&quot;)
Response.Write &quot;Please click <a href='javascript:history.back(1)'>here</A> to type in your name&quot;
Response.Write (&quot;</font>&quot;)

end if


if strSubject = &quot;&quot; then
Response.Write (&quot;<font face='verdana' size='2' color='navy'>&quot;)
Response.Write &quot;Please click <a href='javascript:history.back(1)'>here</a> to type in your subject&quot;
Response.Write (&quot;</font>&quot;)

end if

if strMessage = &quot;&quot; then
Response.Write (&quot;<font face='verdana' size='2' color='navy'>&quot;)
Response.Write &quot;Please click <a href='javascript:history.back(1)'>here</a> to type in your message&quot;
Response.Write (&quot;</font>&quot;)

end if

if strEmail = &quot;&quot; then
Response.Write (&quot;<font face='verdana' size='2' color='navy'>&quot;)
Response.Write &quot;Please click <a href='javascript:history.back(1)'>here</a> to type in your Email address&quot;
Response.Write (&quot;</font>&quot;)

end if

Response.End
end if

objRS.AddNew
objRS(&quot;Name&quot;) = strName
objRS(&quot;Subject&quot;) = strSubject
objRS(&quot;Message&quot;) = strMessage
objRS(&quot;Email&quot;) = strEmail
objRS(&quot;Date&quot;) = strDate
objRS(&quot;Time&quot;) = strTime


objRS.Update

Response.Write &quot;<center>The guestbook has been updated with your message</center>&quot;
Response.Write &quot;<center>Please click <a href='gbook.asp'>here</A> to go back to the guestbook</center>&quot;


%>
</center>
</BODY>
</HTML>
 
The easiest way to ensure that you only get one error message at a time is to use an elseif:

if strName = &quot;&quot; then
''code goes here

elseif strSubject = &quot;&quot; then
''code goes here

elseif strMessage = &quot;&quot; then
''code goes here

elseif strEmail = &quot;&quot; then

end if
 
Hello Juanita

I have pasted your code in to the .asp file I had and you're right! Now, if I deliberately leave off the name and click on Submit, a page tells me to go back and fill in 'name'. It does this for all the fields which is what I was looking for.

One problem, though, is that when I actually DO complete the form properly - all fields complete -I still get a message asking me to go back to complete the e.mail field!

If it's not one problem, it's another!

This would seem to me that the program is more or less saying: &quot;If the e.mail field of your form is correctly filled in, then still go back and ask the user to fill it in again&quot;.

Thanks for any light you may be able to shed on this.

Huitzilopochtli
 
After you request the email, write it to the screen to make sure it is the value you are expecting.

strEmail = Request.Form(&quot;txtEmail&quot;)
Response.write(&quot;email is &quot; & strEmail & &quot;<br>&quot;)

I can't see any reason that you would get that message even if you have a valid email, so check the value. If it still happens and the value is what it is supposed to be, post your new code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top