VBScript运行两次,一次加载页面,一次提交。只需要提交?

时间:2012-09-11 12:32:48

标签: vb.net asp-classic vbscript

我觉得我在这里遗漏了一些东西..我在vbscript中添加了一些不同的东西,试着让它只在点击提交按钮而不是两次时运行(第二次页面加载然后再打开提交),但它要么打破了,要么不起作用。任何帮助这个初学者程序员将不胜感激。如果你需要html,请告诉我。编辑:仍在寻求帮助! :(

<% Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set MyMail = CreateObject("cdo.message")
MyMail.From = mailFrom
MyMail.To = mailTo
MyMail.Subject = mailSubject
MyMail.HTMLBody = mailMessage
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
MyMail.Configuration.Fields.Update
MyMail.Send
Set MyMail = nothing
End Sub

Dim mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword

mailFrom = Request.form(example)
mailTo = "example"
mailSubject = "example"
mailMessage = "example"
mailServer = "example"
mailUsername = "example"
mailPassword = "example"

Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
%>

1 个答案:

答案 0 :(得分:1)

如果Request.form(example) = "",那么页面不是表单提交的结果(或者表单是在没有此数据的情况下提交的)那么;

if Request.form(example) <> "" then
   'is a form submission
   .. email code
end if

如果您想更准确地区分提交,请在表单中添加一个常量隐藏字段

<input type="hidden" name="sendemail" value="1" />

并查找Request.form("sendemail") = "1"