我正在创建一个简单的表单,其中包含参考代码和电子邮件地址,存储电子邮件地址,然后发送电子邮件。
表单有一些脚本,用于检查表中是否已存在电子邮件地址,还查找另一个表以检查其输入的引用代码是否存在于另一个表中。
在我的页面中,如果代码不存在和/或电子邮件地址存在,我会显示一条错误消息。但是,如果表单成功提交,那么我希望将表单替换为感谢信息。
这是我页面中的代码;
<%
sys_message = ""
If (Request.Form("form_submit") <> "") Then
%><!--#include file="doreferral.asp"--><%
End If %>
[...]
<% If(sys_message <> "") Then
Response.Write(sys_message)
End If %>
<form action="referral.asp#msg" name="frmRegister" id="form_referral" method="post">
<input name="fldCode" type="text" class="quick-referral-input" id="fldCode" value="Enter agent code" onblur="if(this.value=='')
this.value='Enter agent code';" onfocus="if(this.value=='Enter agent code') this.value='';"/>
<input name="fldEmail" type="text" class="quick-referral-input" id="fldEmail" value="Enter email address" onblur="if(this.value=='')
this.value='Enter email address';" onfocus="if(this.value=='Enter email address') this.value='';"/>
<input type="hidden" name="form_submit" value="submitted" />
<input type="image" class="quick-referral-submit" src="images/homepage/quick-referral-submit.gif" value="submit" alt="Submit button"
onClick="checkSignup();">
</form>
表单使用doreferral.asp页面进行插入/检查;
<%
fldCode = replace(request.Form("fldCode"),"'","")
fldEmail = replace(request.Form("fldEmail"),"'","")
'' //Check the submitted email against existing ones in the database
set conn = server.CreateObject("ADODB.connection")
conn.open(application("DATABASE"))
qs = "SELECT COUNT(ReferredEmail) AS 'Count' FROM TenantReferral WHERE ReferredEmail = '" & fldEmail & "'"
set rs = conn.Execute(qs)
countEmail = rs("Count")
set rs = nothing
conn.close
set conn = nothing
If(countEmail >= 1) Then
sys_message = sys_message & "<p class='referral-thanks'>This email address has already been referred.</p>"
End If
''//Check the submitted code against existing ones in the database
set conn = server.CreateObject("ADODB.connection")
conn.open(application("DATABASE"))
qs = "SELECT COUNT(AgentReferralCode) AS 'CountCodes' FROM Customers WHERE AgentReferralCode = '" & fldCode & "'"
set rs = conn.Execute(qs)
CountCode = rs("CountCodes")
set rs = nothing
conn.close
set conn = nothing
If(CountCode < 1) Then
sys_message = sys_message & "<p class='referral-thanks'>The referral code does not exist.</p>"
End If
'' //Only Process the SQL if there is no sys_message
If(sys_message = "") Then
SQLfields = SQLfields & "ReferredCode, "
SQLvalues = SQLvalues & "'"& Trim(fldCode) &"', "
SQLfields = SQLfields & "ReferredEmail"
SQLvalues = SQLvalues & "'"& Trim(fldEmail) &"'"
SQL = SQL & "INSERT into TenantReferral ("& SQLfields &") VALUES ("& SQLvalues &")"
response.Write(SQL)
set conn = server.CreateObject("ADODB.connection")
conn.open application("DATABASE")
SET rs = conn.execute(SQL)
''//Email code goes here
response.Redirect("referral.asp")
End If
%>
我想知道是否有人可以发现任何我可以更改/添加的内容以显示感谢信息,但不显示表单。我在表单周围尝试了一些If语句,但没有成功。
谢谢。
答案 0 :(得分:1)
很容易做到,你只需稍微移动你的逻辑。
逻辑可能有点像这样:
这样您就不必担心天气会显示表格,如果一切正常,它只会重定向,页面的其余部分将无法处理。
理想情况下,我会将您的include中的代码包装到函数/ sub中并将其包含在顶部,然后您可以在代码中的任何位置调用它&lt;%= ValidateForm()%&gt;或类似的。
当然你应该切换到ASP JScript:P