p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   Validation of Page (http://p2p.wrox.com/showthread.php?t=14448)

qazi_nomi June 21st, 2004 03:51 AM

Validation of Page
 
Hi,

I'd like to know how to validate a form. When the form is submitted and there are errors in the form fields, i'd like to see the same form again, but with the wrong field turned red and empty, and the proper filled field should contain their data. this should all happen on the same page.
Thanks


Love 4 all

happygv June 21st, 2004 05:58 AM

Hi,

You can use something like this to achieve that.

Code:

<%
Dim testVal, TestValErrMsg

If Request.form("Submit")<>"" then
    testVal=Request.form("testVal")
    If len(trim(testVal))=0 then
        TestValErrMsg = "Cannot be Empty String.Please re-enter the value"
    Else
     ''' Process the value, may be store that in db and then,
     ''' Redirect to another page, that says, the values are stored.
     ''' or say that values are processed in the same page at the top
     ''' and clean up the values of all the form variables, without redirecting to another page.
     End If
End If
%>

...
...
...

<Form action="" method="post">
    <input type="text" name="testVal" value="<%=testVal%>">
<%
    If len(trim(TestValErrMsg))>0 then Response.write TestValErrMsg
%>
    <input type="Submit" name="Submit" value="Submit">
</Form>

Hope that helps.
Cheers!

_________________________
-Vijay G
[8]Strive for Perfection[8]

qazi_nomi June 21st, 2004 06:03 AM

I have a lot of information on that page and if there is error then User finds an error message but the information loss how I can save that information

Love 4 all

madhukp June 21st, 2004 06:18 AM

Unfortunately, there is no way to automatically post the value to the form back, I think.

Please go through my reply for the issue "Different objects send in links" which you started on 18th June. I am quoting it here again. for your easiness.
--------------------------------------------------------------------------------------------------

A change in the page structure is needed.

You have a registration page which checks the details of the visitor submitted through a page say - registration.asp. Let that page be registrationFB.asp. i.e. registration.asp collects the visitor details initially and submits to registrationFB.asp

You have a page which will be shown after successful registration. Let that page be welcome.asp

The form on registrationFB.asp should submit to the same page. The code structure in registrationFB.asp is as follows.

' Collect the posted values from registration.asp in variables

' The validation script

' Initialize a variable strErrorMessage as an empty string. (strErrorMessage="")

' check whether fields are empty.

' check whether login exists.

' after each validation check you need to concatenate the error message to the variable strErrorMessage.

' if(strErrorMessage="") then

' show the error message

' show the form. In the form show the values. You can get the values from the variables into which you stored them at the beginning of the page. Please remember that this form gets submitted to registrationFb.asp.

' else

' go to welcome.asp

' end if
----------------------------------------------------------------------------------------------

happygv June 21st, 2004 06:44 AM

Hi Madhukp,

Quote:

quote:Unfortunately, there is no way to automatically post the value to the form back, I think.
I am not sure what does automatically post the value to the form back mean here?

Quote:

quote:You have a registration page which checks the details of the visitor submitted through a page say - registration.asp. Let that page be registrationFB.asp. i.e. registration.asp collects the visitor details initially and submits to registrationFB.asp

You have a page which will be shown after successful registration. Let that page be welcome.asp

The form on registrationFB.asp should submit to the same page. The code structure in registrationFB.asp is as follows.
I don't understand why one should have registration.asp and registrationFB.asp, for this?

I assume both the pages are going to have the form with similar fields in them. Why should the structure that you suggest on registrationFB.asp be not written on registration.asp itself?

Cheers!

_________________________
-Vijay G
[8]Strive for Perfection[8]

qazi_nomi June 21st, 2004 06:50 AM

Dears I have a page Registration.asp and Confirm.asp and on confirm.asp if any type of error then I wil redirect to Registration.asp.
I want to know when it wil redirect then where it stores the information

Love 4 all

madhukp June 21st, 2004 07:06 AM

I mean, without writing any code, there is no way to get back the previously typed values. In ASP.Net, there is a way to retrieve posted values incase there is some error.

Yes, you can post the form to the same page and have the same form. But since the form is big and it involves lot of variables (to temporarily save the posted values), it will make the pages lengthy. (I hate long pages !!)

gazi_nomi,

If you are using same page for showing form as well as validating and storing into db, you need to initialize all the variables which will be used to store the posted values.

happygv June 21st, 2004 07:17 AM

qazi_nomi,

Quote:

quote:I have a page Registration.asp and Confirm.asp and on confirm.asp if any type of error then I wil redirect to Registration.asp. I want to know when it wil redirect then where it stores the information
That way it is not easy to achieve what you posted in your original post.

If you got to show errors in RED for fields that do not conform to your validation rules and should also show the values in its form controls besides the ERROR in red, then you cannot check for error in your confirm.asp.

To achieve that, you got the post the values to registration.asp in which you can check for the values and assign error message for relevant fields that do not conform to the validation rules and show them besides the relevant fields on the same page. If everything is fine then you can store them into DB if you want, and redirect to confirm.asp, where you say, data has been stored successfully.

That is probably what I have posted in my first reply to this post.

Cheers!

_________________________
-Vijay G
[8]Strive for Perfection[8]

happygv June 21st, 2004 07:21 AM

Hi Madhukp,

But I feel the way of using 2 such pages (with similar form fields in them) is going to pose you problem in maintaining them and I am sure, one would have to code more than what it can be done in one such page.

Cheers!

_________________________
-Vijay G
[8]Strive for Perfection[8]

qazi_nomi June 22nd, 2004 12:34 AM

I have two pages for that one is for registraton and one is for its confirmation.
If there is any error occured in confirmation page then all information of registration
page wil be lost.
It is only problem and one solution which is in my mind that I think in javascript there is a method for sending page back but i dont know how to use that
If any one knows then guide me PLZ

Love 4 all


All times are GMT -4. The time now is 04:33 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.