Hi there,
I'm creating a simple form that takes a referal code and email address, stores the email address and then sends an email.
The form has some script that checks if the email address already exists in the table and also looks up another table to check to see if the referral code that they are entering exists in the other table.
In my page I have an error message displaying if the code doesn't exist and/or if the email address exists. However, if the form submits successfully, then I want the form to be replaced by a thank you message.
This is the code in my page;
<%
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>
The form uses a doreferral.asp page to do the insert/checking;
<%
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
%>
I wondered if anyone could spot anything that I could change/add to display a thank you message, but not display the form. I have tried a few If statements around the form, but without success.
Thank you.