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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sends mail on every refresh. 1

Status
Not open for further replies.

guyphil

Programmer
Nov 2, 2004
27
IL
Iv'e built an online catalog/ASP application in which a visitor can click on checkboxes selecting products, and then I get this info (using JMail).

This all works great, it's just that whenever a visitor refreshes a page, I get a blank email.

How do I prevent the app from send an email on refresh?

Thanks.

The Code: (mail is at the bottom)

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<% Response.buffer=true%>
<html>
<head>
<title>Asscher Cut</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
td
{color:white}
</style>
<script language="JavaScript">

function submitForm(x){
form = x.form;
form.submit();
self.location = "stockindex.html";
}
</script>
</head>

<body bgcolor="#221a41" leftmargin="0" bgproperties="fixed" topmargin="0" rightmargin="0" topmargin="0" >
<form action="<%= Request.ServerVariables("dataresaults.asp") %>" method="post" >

<br>
<table border="0" bgcolor="#221a41" align="center" cellpadding="0" cellspacing="0">
<tr valign="top">
<td>
<table border="1" align="center" height="80" cellpadding="2" cellspacing="2">


<tr>
<td align="center" colspan="10"><font size="5" face="Arial" color="#FFFFFF">ASSCHER CUT<BR>COLLECTION CLEAN - D,E,F,G</font></td>
</tr>
<tr>
<th align="center" bgcolor="FB9C30" colspan="10"><font size="2" face="Arial" color="#FFFFFF">Please choose the goods you are intersted in,
and click the "Confirm"<br> button to mail us. Will contact you as soon as possible. </font></th>
</tr>
<tr>
<td align="center" colspan="10"><font size="2" face="Arial" color="#FFFFFF">SIZES : M"M</font></td>
</tr>


<td align="center"><font face="arial" size="2" color="#FFFFFF">2.5X2.5</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">2.8X2.8</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">3.0X3.0</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">3.3X3.3</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">3.5X3.5</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">3.8X3.8</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">4.0X4.0</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">4.2X4.2</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">4.3X4.3</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">4.5X4.5</font></td>

</tr>
<tr>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="2.5X2.5"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="2.8X2.8"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="3.0X3.0"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="3.3X3.3"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="3.5X3.5"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="3.8X3.8"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="4.0X4.0"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="4.2X4.2"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="4.3X4.3"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="4.5X4.5"></td>

</tr>
<td height="50"></td>
<tr>
</tr>
<td colspan=3></td>
<td align="center" colspan="4"><font size="2" face="Arial" color="#FFFFFF">WEIGHT</font></td>
<tr>
<td colspan=3></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">58+</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">3/4</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">009</font></td>
<td align="center"><font face="arial" size="2" color="#FFFFFF">4/4</font></td>

</tr>
<tr>
<td colspan=3></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="58+"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="3/4"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="009"></td>
<td align="center">&nbsp;<input name="multiple" type="checkbox" value="4/4"></td>

</tr>
<tr>
<th align="center" bgcolor="FB9C30" colspan="10"><font size="2" face="Arial" color="#FFFFFF">Feel free to leave any comments you may have,
<br> or information regarding quantities. </font></th>
</tr>
<tr >
<td align="center" colspan="10"><textarea name="freetext" cols="60" rows="4"></textarea></td>
</tr>


<tr>
<td colspan="2"><input type="button" value="confirm" onClick="submitForm(this)"/>
<br>
<%=session("visitor_id")%>
<strong>
<%
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file
Dim sql
dim sid
' MapPath of virtual database file path to a physical path
strDBPath = Server.MapPath("db_dvash.mdb")
Set cnnSimple = Server.CreateObject("ADODB.Connection")
cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
Set rstSimple=Server.CreateObject("ADODB.Recordset")' connection string and recordset
sid=session("visitor_id") 'from session variable
sql="SELECT * FROM USERS WHERE VISITORID=" & sid ' get all visitor info from db
rstSimple.Open sql, cnnSimple


Dim orders
dim email
dim text
dim cut
dim orderstring
text=Request.Form("freetext") ' get textbox
email=rstSimple("EMAIL") ' get email address

cut= "Asscher- "
orderstring=Request.Form("multiple") & email &" Comments: " & text 'all the info
orders= cut & orderstring

dim msg
set msg = Server.CreateOBject( "JMail.Message" )
msg.Logging = true
msg.silent = true
msg.From = "yoram@ydvash.co.il"
msg.FromName = "Asscher"
msg.AddRecipient "diamond@bezeqint.net"
msg.Subject = "this is a test"
msg.AppendHTML("<b>" & orders & "</b>")
msg.Charset = "windows-1255"
msg.Send( "smtp.012.net.il:25" )


%>
</strong>
</td>

</tr>
</table>

</form>


</body></html>
<%

rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
%>


 
Hiya

I think the problem is because you have everything happening at once on the same page, so all of the code runs every time the page is loaded.

I would suggest using a Select statement to separate the mail code from the form code, based on the value of an 'action' variable.

For example

Select Case Request.QueryString("action")
Case "processform"

'Put the mail code in here
'Once the mail has been sent, redirect back to the page to display the form

Response.Redirect("thispage.asp")

Case Else

<form action="thispage.asp?action=processform">
'form contents
</form>

End Select


'Put the main form in here

End Select

This way the form will only ever get processed and the mail sent after it has actually been submitted, not just on a page refresh.
You could do the same thing by splitting the page into two pages completely but this way it keeps everything inside one page for ease of use.

hope this helps!


Nick (Webmaster)

 
another option is to set a session value...

Known is handfull, Unknown is worldfull
 
How would I go about it by setting a session value?
 
Thanks Howard,

There's just one thing I'm not clear on.
How do I base the form code on the value of an 'action' variable? How do I 'capture' the event of submition?
In other words, How do I say in VBscript:" When I click on the submit button, Select Case...."

Thanks in advance.

Guyphil
 
Hiya

You can do this either by sending an extra form item over or attaching a variable to the end of the action of the form e.g.

<form action="thispage.asp?action=submit">
</form>

or

<form action="thispage.asp">
<input type="hidden" name="action" value="submit">
</form>

Then all you need to do is check for the presence of this variable e.g.

If Request.QueryString("action") = "submit" Then..
or
If Request.Form("action") = "submit" Then...

or using the Select
Select Case Request.QueryString("action")
Case "submit"

Case Else

End Select

Hope this makes sense

Nick

Nick (Webmaster)

 
Place the following on top of page.
<% Session("Count") = Session("Count") + 1 %>


Use this where you send the mail.

<%
If Session("Count") = 1 Then
(SEND THE MAIL)
End If
%>
This way the mail can only be sent once, i.e., when the count is one. If you need to send it again reset the count to zero befor calling the page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top