|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
form submitting to self and not redirecting - how to?
Hi
I got this code from http://www.asphonolulu.com/Samples/...mvalidation.asp 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 a validate page where I will set up my connection etc and submit to a db. Where am I going wrong and how can I get the form (after doing the validation checks) to submit to another page? Also not sure awhat the DebugQS is 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> |
|
#2
|
||||
|
||||
|
there is a better way
if you want post in the forum the feilds that you are using in the form and i will write the code......
|
|
#3
|
|||
|
|||
|
Thanks I appreciate this. I am still learning about functions.
Does it all have to be done by QS? I have about 40 fields and would rather do it by POST method. Is that possible? I tried changing QS to request.form but it didn't like that. Definitely would prefer to post all the fields once it has done the validation and everything's ok. If you could work with 5 fields then I will get the idea and add all the others(too much work for you otherwise). The fields are Title(dropdown), FirstName, Surname, Email, EmailReenter, NINumber. There are 2 things I'm not sure how to deal with. 1. Email and EmailReentered are not mandatory although *if someone does enter a value * then I need to perform the validation and check that they match. 2. NINumber is actually made up of 9 small input boxes for each individual number. The first 2 need to be alpha, next 6 numeric and last 1 alpha. If I check using this code then it puts 'required' after every single input box and messes up the form and alignment. Would there be a way to do one check for all of the NINumbers and then return a single true or false so that only one 'required' message comes up? Once the validation is succesful, would it be possible to send the values by post method rather than QS? Let me know if there's anything else you need to know. Cheers Lee |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > form submitting to self and not redirecting - how to? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|