Hi
I got this code from
I have stripped it down to the basics for example purposes.
At the moment, if user completes all required textboxes, it submits to itself. I need to set it so that if the form is completed properly, it sends all the values to validate page where I will set up my cnnection etc and submit to a db. Where am I going wrong and how can I get the form (after doing checks) to submit to another page?
Hm, not sure also what the DebugQS ia all about. Do I need to keep this in my code?
Much appreciated!
Lee
<%@ Language=VBScript %>
<% Response.Buffer = true %>
<%
Dim bError
Dim bIsSubmitted
bError = false
' IsSubmitted is hidden field in form
If Request.QueryString("IsSubmitted"
= "" Then
bIsSubmitted = false
Else
bIsSubmitted = true
End If
'Response.Write "bIsSubmitted: " & bIsSubmitted & "<br>"
Function EmailValidation(sFieldname, error)
If bIsSubmitted Then
Dim objRegExp
Set objRegExp = New regexp
objRegExp.Pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
If Not objRegExp.Test(Request.QueryString(sFieldname)) Then
EmailValidation = " <font color=""red"">""" & error & """</font>"
bError = true
Else
EmailValidation = ""
End If
End If
End Function
Function RequiredFieldValidation(sFieldname, error)
RequiredFieldValidation = ""
If bIsSubmitted Then
If Trim(Request.QueryString(sFieldname)) = "" Then
RequiredFieldValidation = " <font color=""red"">""" & error & """</font>"
bError = true
End If
End If
End Function
Sub DebugQS()
Response.Write "<b>ScriptName: " & ScriptName() & "</b><br>"
Response.Write "<b>QueryString Variables: </b><br>"
For i=1 to request.QueryString.count
response.write " " & request.QueryString.key(i) & " = """ & request.QueryString.item(i) & """<br>"
If InStr(request.QueryString.item(i), ","
> 0 Then
For Each item in request.QueryString.item(i)
Response.Write " " & request.QueryString.key(i) & " = """ & item & """<BR>"
Next
End If
Next
End Sub
Function ScriptName()
ScriptName = Right(Request.ServerVariables("SCRIPT_NAME"
, Len(Request.ServerVariables("SCRIPT_NAME"
) - InStrRev(Request.ServerVariables("SCRIPT_NAME"
, "/"
)
End Function
Sub DisplayForm()
%>
<form method="GET">
<input type="hidden" name="IsSubmitted" value="Yes">
<table class="insettabletop" width="480" align="center" border="0" cellspacing="4" cellpadding="4">
<tr>
<td align="left">First Name(s) in full</td>
<td align="left" width="5"> </td>
<td align="left"><input type="text" name="FirstName" class="inputpension" value="<%=Request.QueryString("FirstName"
%>" /><img src="images/required_image.gif" width="10" height="9" alt="Expat Financial" />
<%=RequiredFieldValidation("FirstName", "*"
%>
</td>
</tr>
</table>
</form>
<%
DebugQS
End Sub
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Form Validation Test</title>
</HEAD>
<BODY>
<h3>Form Validation Test</h3>
<%
If Not bIsSubmitted Then
DisplayForm
Else
DisplayForm
Response.Write "<br><a href=""javascript:void(location.replace('formtest.asp'));""><font color=""blue"">Start Again</font></a>"
If Not bError Then
' Clear headers and start over
Response.Clear
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Form Validation Test</title>
</HEAD>
<BODY>
<h3>Form Validation Test</h3>
<%
DebugQS
' Update the DB
Response.Write "Updating the DB...<br>"
' Report errors (or crash)
' Close or whatever button(link)
Response.Write "<br><a href=""javascript:void(location.replace('formtest.asp'));""><font color=""blue"">Start Again</font></a>"
End If
End If
%>
</BODY>
</HTML>
I got this code from
I have stripped it down to the basics for example purposes.
At the moment, if user completes all required textboxes, it submits to itself. I need to set it so that if the form is completed properly, it sends all the values to validate page where I will set up my cnnection etc and submit to a db. Where am I going wrong and how can I get the form (after doing checks) to submit to another page?
Hm, not sure also what the DebugQS ia all about. Do I need to keep this in my code?
Much appreciated!
Lee
<%@ Language=VBScript %>
<% Response.Buffer = true %>
<%
Dim bError
Dim bIsSubmitted
bError = false
' IsSubmitted is hidden field in form
If Request.QueryString("IsSubmitted"
bIsSubmitted = false
Else
bIsSubmitted = true
End If
'Response.Write "bIsSubmitted: " & bIsSubmitted & "<br>"
Function EmailValidation(sFieldname, error)
If bIsSubmitted Then
Dim objRegExp
Set objRegExp = New regexp
objRegExp.Pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
If Not objRegExp.Test(Request.QueryString(sFieldname)) Then
EmailValidation = " <font color=""red"">""" & error & """</font>"
bError = true
Else
EmailValidation = ""
End If
End If
End Function
Function RequiredFieldValidation(sFieldname, error)
RequiredFieldValidation = ""
If bIsSubmitted Then
If Trim(Request.QueryString(sFieldname)) = "" Then
RequiredFieldValidation = " <font color=""red"">""" & error & """</font>"
bError = true
End If
End If
End Function
Sub DebugQS()
Response.Write "<b>ScriptName: " & ScriptName() & "</b><br>"
Response.Write "<b>QueryString Variables: </b><br>"
For i=1 to request.QueryString.count
response.write " " & request.QueryString.key(i) & " = """ & request.QueryString.item(i) & """<br>"
If InStr(request.QueryString.item(i), ","
For Each item in request.QueryString.item(i)
Response.Write " " & request.QueryString.key(i) & " = """ & item & """<BR>"
Next
End If
Next
End Sub
Function ScriptName()
ScriptName = Right(Request.ServerVariables("SCRIPT_NAME"
End Function
Sub DisplayForm()
%>
<form method="GET">
<input type="hidden" name="IsSubmitted" value="Yes">
<table class="insettabletop" width="480" align="center" border="0" cellspacing="4" cellpadding="4">
<tr>
<td align="left">First Name(s) in full</td>
<td align="left" width="5"> </td>
<td align="left"><input type="text" name="FirstName" class="inputpension" value="<%=Request.QueryString("FirstName"
<%=RequiredFieldValidation("FirstName", "*"
</td>
</tr>
</table>
</form>
<%
DebugQS
End Sub
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Form Validation Test</title>
</HEAD>
<BODY>
<h3>Form Validation Test</h3>
<%
If Not bIsSubmitted Then
DisplayForm
Else
DisplayForm
Response.Write "<br><a href=""javascript:void(location.replace('formtest.asp'));""><font color=""blue"">Start Again</font></a>"
If Not bError Then
' Clear headers and start over
Response.Clear
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Form Validation Test</title>
</HEAD>
<BODY>
<h3>Form Validation Test</h3>
<%
DebugQS
' Update the DB
Response.Write "Updating the DB...<br>"
' Report errors (or crash)
' Close or whatever button(link)
Response.Write "<br><a href=""javascript:void(location.replace('formtest.asp'));""><font color=""blue"">Start Again</font></a>"
End If
End If
%>
</BODY>
</HTML>