ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2003, 03:34 PM
leeolive leeolive is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: London
Posts: 43 leeolive User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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 "&nbsp;&nbsp;" & 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 "&nbsp;&nbsp;&nbsp;&nbsp;" & 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"> &nbsp; </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>

Reply With Quote
  #2  
Old November 2nd, 2003, 02:18 AM
LabRaTT's Avatar
LabRaTT LabRaTT is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Boston, MA, USA
Posts: 23 LabRaTT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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......

Reply With Quote
  #3  
Old November 2nd, 2003, 04:37 AM
leeolive leeolive is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: London
Posts: 43 leeolive User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > form submitting to self and not redirecting - how to?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway