form inside a div

J

jp2code

I have some Classic ASP script that is not working at all. By that, I mean
that none of the code seems to execute.

I have the exact same code in another form on another web page, and it does
work.

The only difference between the two that I can see (other than username and
password fields) is that the non-working page contains a form within a div
tag, whereas the working page places the form inside a table.

The form's id is "contact" on both pages.
The div's id is "popup" on the non-working page.
The table on the working page does not use an id.

Have I used a reserved word somewhere?
Can a form with an id be nested within another tag that also has an id?

There are no errors. When the form is submitted, the information should be
validated in the script, but instead I get what looks like the page being
reloaded without its previous values.

I am typically a C++ guy, so it is very possible that I have missed or
overlooked something very basic - but it wasn't the username and password!
I've checked them multiple times.

Thanks in advance!
~Joe

Below is the non-functional version's code:
<%@ Language="VBSCRIPT"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<%

Dim OK

Dim str1Err, str2Err, str3Err, str4Err

Dim strFirst, strLast, strEmail, strMyMessage

Dim strWriteMsg, strEmailValidator, strHtmlBody

OK = True

str1Err = ""

str2Err = ""

str3Err = ""

str4Err = ""

strMyMessage = ""

strWriteMsg = "Write your message here."

strEmailValidator =
"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"

If (Request.Form("5submit") = "Send") Then

strFirst = Request.Form("1FirstName")

If (strFirst = "") Then

str1Err = "<span style='color:red'>Required</span>"

OK = False

End If

strLast = Request.Form("2LastName")

If (strLast = "") Then

str2Err = "<span style='color:red'>Required</span>"

OK = False

End If

strEmail = Request.Form("3Email")

Set regEx = New RegExp

regEx.Pattern = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$"

If (regEx.Test(Trim(strEmail)) = False) Then

str3Err = "<span style='color:red'>Incorrect format</span>"

OK = False

End If

Set regEx = Nothing

strMyMessage = Request.Form("4Message")

If (strMyMessage = "") Or (strMyMessage = strWriteMsg) Then

str4Err = "<span style='color:red'>Required</span>"

OK = False

Else

strWiteMsg = ""

End If

If (OK = True) Then

Dim strFrom

strFrom = strFirst & " " & strLast & " <" & strEmail & ">"

Set objMessage = CreateObject("CDO.Message")

strHtmlBody = "<html><body
style=""background-image:url(http://www.poolranch.com/images/cattle.jpg);
background-position: 0% 50%; background-repeat: repeat-x;"">" & _

"<table style=""width:500px""><tr><td style=""width:300px"">" & _

"<b><font color=""#780000"">Pool Ranch</font></b><br/>" & _

"<b>From:</b> " & strFirst & " " & strLast & " <" & strEmail & ">" & "<br/>"
& _

"<b>Message:</b> <pre>" & strMyMessage & "</pre></td><td
style=""width:150px"">" & _

"<img src=""http://www.poolranch.com/images/dplogo.gif"" alt=""Pool Ranch
Logo"" style=""height:215px; width:185px"">" & _

"</body></html>"


objMessage.Subject = "PoolRanch Contact"

objMessage.From = strFrom

objMessage.To = ' value is hidden

objMessage.HTMLBody = strHtmlBody

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "relay-hosting.secureserver.net"

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 60

objMessage.Configuration.Fields.Update

On Error Resume Next

objMessage.Send

Set objMessage = Nothing

If Err.number = 0 Then

Response.Redirect("../thanks.htm")

Else

strMyMessage = "Send Failed. Your message was not sent. I am so sorry! " & _

"Error # " & CStr(Err.number) & ": " & Err.Description

Err.Clear

End If

End If

Else

strMyMessage = strWriteMsg

if (strMyMessage = "") Then

Response.Write("Your message was not sent.")

end if

End If

%>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Pool Ranch - Contact</title>

<link rel="Stylesheet" type="text/css" href="../poolranch.css"
title="poolranch style" />

<script type="text/javascript" language="JavaScript"
src="../poolranch.js"></script>

<script type="text/javascript" language="JavaScript">

<!--

function Start() {

preload(HOME, "home", "../images/home.gif", "../images/homedn.gif",
"../images/homeov.gif" );

}

//-->

</script>

</head>

<body onload="Start()">

<h1>Contact Form</h1>

<div id="main">

<table>

<tr><td align="center"><img class="lgo" src="../images/dplogo.gif"
alt="dplogo" /></td></tr>

<tr><td class="mnu"></td></tr>

<tr><td class="mnu"><a href="../." onmouseover="imgOver(HOME)"
onmouseout="imgOut(HOME)" onmousedown="imgDown(HOME)">

<img class="btn" id="homeBtn" src="../images/home.gif" alt="Pool Ranch
Homepage" />

</a></td></tr>

<tr><td class="mnu"></td></tr>

<tr><td class="mnu"></td></tr>

<tr><td class="mnu"></td></tr>

<tr><td class="mnu"></td></tr>

<tr><td class="mnu"></td></tr>

<tr><td class="mnu"><a href="http://redangus.org" target="_blank"><img
alt="redangus" src="../images/redangus.png" id="redangus" /></a></td></tr>

</table>

</div>

<div id="popup">

<form id="contact" action="test.asp" method="post">

<input type="hidden" name="subject" value="Message from PoolRanch.com" />

<input type="hidden" name="redirect" value="thanks.htm" />

<table width="550"><tbody>

<tr>

<td align="right" style="width:225px">First Name:</td>

<td align="left"><input type="text" name="1FirstName"
value="<%Request.Form("1FirstName")%>" />

<span><%Response.Write(str1Err)%></span>

</td>

</tr>

<tr>

<td align="right">Last Name:</td>

<td align="left"><input type="text" name="2LastName"
value="<%Request.Form("2LastName")%>" />

<span><%Response.Write(str2Err)%></span>

</td>

</tr>

<tr>

<td align="right">E-Mail (for replies):</td>

<td align="left"><input type="text" name="3Email"
value="<%Request.Form("3Email")%>" />

<span><%Response.Write(str3Err)%></span>

</td>

</tr>

<tr>

<td colspan="2" align="center">Message:<br />

<textarea name="4Message" cols="40"
rows="10"><%Response.Write(strMyMessage)%></textarea>

<span><%Response.Write(str4Err)%></span>

</td>

</tr>

<tr>

<td align="right">&nbsp</td>

<td align="left"><input type="submit" name="submit" value="Send" /></td>

</tr>

</tbody></table>

</form>

</div>

<div style="position: absolute; top: 535px; width: 600px; height: 25px;
left: 180px; text-align: center;" id="home"><a
href="http://www.poolranch.com/">www.poolranch.com</a></div>

</body>

</html>
 
D

Dave Anderson

jp2code said:
...the non-working page contains a form within a div tag, whereas
the working page places the form inside a table.

The form's id is "contact" on both pages.
The div's id is "popup" on the non-working page.
The table on the working page does not use an id.

Have I used a reserved word somewhere?

Doubtful. It is almost impossible to do so, provided you enclose the
attribute values in quotes. HOWEVER, you should take a look at the ID
specification:

id = name [CS]
This attribute assigns a name to an element. This name must
be unique in a document.

http://www.w3.org/TR/html401/struct/global.html#adef-id

By drilling down, you will see that [CS] means it is case-sensitive, and
name tokens have few restrictions:

6.2 SGML basic types
ID and NAME tokens must begin with a letter ([A-Za-z]) and may
be followed by any number of letters, digits ([0-9]), hyphens
("-"), underscores ("_"), colons (":"), and periods (".").

http://www.w3.org/TR/html401/types.html#type-name

You are declaring HTML 4.01 strict, so I would not presume your NAME
attributes, like "1FirstName", are not the problem. Fix those first.

Can a form with an id be nested within another tag that also has an id?
Absolutely.



There are no errors.

There is no client-side scripting in your example, so I presume you mean you
get none of the feedback messages you create during the post-back. It should
be trivial for you to determine which steps are reached. Do so.


When the form is submitted, the information should be validated in the
script, but instead I get what looks like the page being reloaded
without its previous values.

Are you certain the action of the form is the script itself? If you copied
from a working script, you may still be posting to that script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top