Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2004, 10:25 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Non-functioning validation1

Hello one & all ,
The clientside validation i have implemented are not correctly working - a common problem is that form submission occurs irrespective of errors. This is a recurring problem across application and i am unable to solve the problem. Any help would be greatly appreciated. Below is an example of code.Thanks in advance,
larry101

LOGIN PAGE CODE
<HTML>
<HEAD>

<SCRIPT LANGUAGE="VBScript">

 Function RadioGroupValid(radGroup)
   Dim radNo
   RadioGroupValid = False

   For radNo=0 to radGroup.Length-1
     If radGroup(radNo).Checked = True Then
        RadioGroupValid = True
     End If
   Next
 End Function

 Function TextBoxValid(textbox)
  Dim textlen
  TextBoxValid = True
  textlen = Len(textbox)
      If textlen <> 8 Then
              TextBoxValid = False
     End If
 End Function

 Function checkInput)
  If RadioGroupValid(login.usertype)= False Then
     checkInput = False
     MsgBox "You have forgotten to select a usertype",0,"ERROR"
     Exit Function
  End If

  If TextBoxValid(login.username.value)= False Then
     checkInput = False
     MsgBox "The required number of characters for a username is 8",0,"ERROR"
     Exit Function
  End If

  If TextBoxValid(login.password.value)= False Then
     checkInput = False
     MsgBox "The required number of characters for a password is 8",0,"ERROR"
     Exit Function
  End If

 End Function

 Function formValid()

    If checkInput = True Then
       formValid = True
    Else
       formValid = False
    End If
 End Function

</SCRIPT>
<TITLE> </TITLE>
</HEAD>

<BODY>
<CENTER><H2>LOGIN</H2></CENTER>

<FORM NAME="login" onSubmit="formValid()" ACTION="CheckLogin.asp" METHOD="POST">

Please indicate the type of user you are by selecting from either
<BR>
<input type="radio" name="usertype" value="0">Placement Co-ordinator
<BR>
<input type="radio" name="usertype" value="1">Student
<BR>
<BR>
Please enter both your Username and Password.
<BR>
<BR>
Username : <input type="text" name="username" value="" size="8" maxlength="8">
<BR>
Password : <input type="password" name="password" value="" size="8" maxlength="8">
<BR>
<BR>
<input type="Submit" name="Submit" value="Login">
<input type="Reset" name="Reset" value="Clear">
<BR>
<BR>
</FORM>
</BODY>
</HTML>

Problem : when ok button on MsgBox ( which indicates the error ) is clicked , the form submits to the page in the ACTION attribute which redirects the user back to the login page. There are a couple of problems :
- when the user is returned to the login page , the previously entered information is automatically erased. Should the MsgBox when clicked not keep the user on the same page and leave any entered information intact ? This problem of a form submitting when incorrect/invalid input entered is occurring on several pages across the application I am working on. As can be seen , I am using VBScript for client-side validation and I want to keep this intact. Any suggestions what might be causing this problem ?
- is it possible to send a MsgBox back to the login page indicating that the users information cannot be located in the database in conjunction with a Response.Redirect to the login page ?
- when a Response.Redirect is used in a page to another page any information that had been entered by the user is erased. For example , user inputs data into a form which is submitted to a database , next page displayed indicates data submitted successfully. Upon clicking to return to the form , the user finds that all the fields are empty/default value. Again , any suggestions ?


 
Old September 16th, 2004, 08:07 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi,
    I just included your include file code in the asp file for checking the flow.now you can place this code in your include file.I made some corrections to your code. Instead of using "submit button" i used "button" and i called that event in that tag only. I removed "action" from the form tag and placed in the "formValid()" function. After checking all the validations if every thing fine you are not assigning "true" to "checkInput" in the function "checkInput". Same corrections i made for the 2nd program also.
If u dont understand mail me back..
Thanks
suresh


-------------------------------
<%@ Language=VBScript %>
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">

    Function TextBoxValid(textbox)
      Dim textlen
      TextBoxValid = True
      textlen = Len(textbox)

      If textlen <> 8 Then
         TextBoxValid = False
      End If
    End Function

    Function checkInput()

      If TextBoxValid(ChangePass.NewPassword.value)= False Then
         checkInput = False
         MsgBox "The required number of characters for a password is 8",0,"ERROR"
         Exit Function
      End If

      If TextBoxValid(ChangePass.ConfirmNewPassword.value)= False Then
         checkInput = False
         MsgBox "The required number of characters for password confirmation is 8",0,"ERROR"
         Exit Function
      End If

      If ((ChangePass.NewPassword.value) <> (ChangePass.ConfirmNewPassword.value)) Then
         checkInput = False
         MsgBox "The new password you entered does not match the confirm password.Please re-enter",0,"ERROR"
         Exit Function
      End If
        checkInput = True

    End Function

    Function formValid()
      If checkInput = True Then
        formValid = True
         document.ChangePass.action = "UpdatePassTable.asp"
         document.ChangePass.submit
      Else
        formValid = False
      End If
    End Function

</SCRIPT>

<TITLE>Update User Password</TITLE>
</HEAD>






<BODY>
<FORM NAME="ChangePass" ACTION="UpdatePassTable.asp" METHOD="POST">
Old Password :&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbs p&nbsp&nbsp&nbsp&nbsp&nbsp
<INPUT TYPE="Password" NAME="OldPassword" SIZE="8" MAXLENGTH="8">
<BR>
<BR>
New Password :&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbs p&nbsp&nbsp&nbsp
<INPUT TYPE="Password" NAME="NewPassword" SIZE="8" MAXLENGTH="8">
<BR>
Confirm New Password :
<INPUT TYPE="Password" NAME="ConfirmNewPassword" SIZE="8" MAXLENGTH="8">
<BR>
<BR>
<INPUT TYPE="Button" VALUE="Submit" onclick="formValid()">
&nbsp
&nbsp
<INPUT TYPE="Reset" VALUE="Reset">

<BR>
</TABLE>
</FORM>
</BODY>
</HTML>






Similar Threads
Thread Thread Starter Forum Replies Last Post
String replace not functioning properly ghari ASP.NET 1.0 and 1.1 Professional 3 January 27th, 2006 12:16 AM
Multi Functioning Combo Boxes / Probs socoolbrewster Access 3 March 3rd, 2005 04:36 AM
Dynamic freport list not functioning dbkester Access 0 December 28th, 2003 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.