Print Page | Close Window

Form Validating

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=842
Printed Date: 29 March 2026 at 6:02am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Form Validating
Posted By: maniva
Subject: Form Validating
Date Posted: 08 March 2003 at 5:11pm

Dear Friends,
I've a form with some fields to be cheked.

I've a page to check the fields and then if all are ok then update or write a file.

My problem is that when a field is wrong I would like to display the form page with a message near the field wrong and the value into the rest without retype all the value.

I can do all the thing except to have the fields filled. 

Please Help.



-------------
Ivano Mangiarotti



Replies:
Posted By: michael
Date Posted: 08 March 2003 at 6:45pm
Well if youn do the validation in asp then you need to do a postback of the form values, then setting the value to something like <input type="text" value="<%=Request("bla")>


Posted By: maniva
Date Posted: 09 March 2003 at 8:29am

Thanks Michael,
but  How to do a postbak ?

Bye



-------------
Ivano Mangiarotti


Posted By: michael
Date Posted: 09 March 2003 at 10:03am
what I ment, after you posted to an asp page, did the validation now if there is an error you would do something like response.redirect "startpage?error......your parameters here" or you do it with an autosubmitted form. anyway, this is what I ment.


Posted By: maniva
Date Posted: 09 March 2003 at 3:07pm

What I'm using now is exactly response.redirect whith the error code.
I can pass back the error type like 1 is wrong name 2 Insert code 3 .... Etc. But if I wont to allow the user to don't retype all the infoemation I dont wont to have a response.redirect 1Km long.

Do you know another way ?

Bye.



-------------
Ivano Mangiarotti


Posted By: Gullanian
Date Posted: 09 March 2003 at 4:46pm

Well have the form again on the validation page with the values submitted loaded in the form again



Posted By: maniva
Date Posted: 10 March 2003 at 2:16am
Sound good !

I will try

-------------
Ivano Mangiarotti


Posted By: Gary
Date Posted: 10 March 2003 at 3:00am

Why not do it all in the original page - use javascript to validate the form. If validation fails, then display (alert) a message. If it passes, then submit the form.



Posted By: maniva
Date Posted: 10 March 2003 at 3:12am

I don't like alert in javascript.
I would like to display a red message near the wrong field.



-------------
Ivano Mangiarotti


Posted By: Gary
Date Posted: 10 March 2003 at 3:19am

You could do something else with javascript.....

Change the background color of all form elements that are incorrect/incomplete.

Place somekind of image/message next to each element and set the visibility property to hidden. When you run the validation script, change the visibility to visible on all elements that fail.

This would be a lot easier and economical than validating on a different page - especially if you're going to redirect back when validation fails.



Posted By: maniva
Date Posted: 10 March 2003 at 3:38am

Could you give me an example with explanation in changing colors etc.

I've some data field, numeric and text.

Thanks a lot

 



-------------
Ivano Mangiarotti


Posted By: Gary
Date Posted: 10 March 2003 at 4:09am

Here you go.....
Basically there are 2 inputs on the form which are validated (one to see if anything has been entered and the other to check if a number > 0 has been entered).

Hope this helps

<script language="Javascript">
function ValidateForm()
{
 document.myForm.ErrCheck.value = "";
 ErrMsg = 'ERROR - Incomplete Data' + '\n' + '\n';
 if (document.myForm.txtA.value == "")
  {
  ErrMsg = ErrMsg + 'You need to specify your name.' + '\n';
  document.copyrequest.ErrCheck.value = "Error";
  document.copyrequest.FileName.style.backgroundColor='#ff0000';
  }

 if (isNaN(document.myForm.intB.value) || document.myForm.intB.value < 1)
  {
  ErrMsg = ErrMsg + 'You need to specify your age.' + '\n';
  document.myForm.ErrCheck.value = "Error";
  }

 if (document.copyrequest.ErrCheck.value == "Error")
   {
   alert(ErrMsg);
   }
 else
 {
  document.copyrequest.submit();
 }
}
</script>

<form name="myForm" action="page.asp" method=-"post">
<input name="ErrCheck" type="hidden">
Name: <input name="txtA" type="text">
Age (Years): <input name="intB" type="text">
</form>

<input type="button" value="Valid" onClick="ValidateForm()">



Posted By: Bunce
Date Posted: 10 March 2003 at 3:30pm
Originally posted by Gary Gary wrote:

You could do something else with javascript.....

Change the background color of all form elements that are incorrect/incomplete.

Place somekind of image/message next to each element and set the visibility property to hidden. When you run the validation script, change the visibility to visible on all elements that fail.

This would be a lot easier and economical than validating on a different page - especially if you're going to redirect back when validation fails.

If this is any sort of serious site, I wouldn't rely on client-side validation. It can be circumvented quite easily.

Client-side validation is for the 'cosmetic benefit' of your users. A complete server-side validation process should always be performed, irrespective of whether you use client-side validation or not.

http://www.adopenstatic.com/resources/code/UIValidation.asp - http://www.adopenstatic.com/resources/code/UIValidation.asp

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: maniva
Date Posted: 11 March 2003 at 1:56am

Thank you vary much Gary.

I will  try immediately



-------------
Ivano Mangiarotti



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net