Connecting Tech Pros Worldwide Forums | Help | Site Map

Ways to validate form before submitting

Wysiwyg
Guest
 
Posts: n/a
#1: Nov 19 '05
I need to validate a form to ensure that all of the fields add up correctly.
I can't do this while the user is entering data since validation needs to be
done after the entry is completed. What's the "best" way to validate prior
to submitting?

I could add an onsubmit attribute to the form which executes the validation
in Javascript. That way the response doesn't need to be sent before
validation takes place. Is this pretty much the way to do it?

Thanks!
Bill



Scott Allen
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Ways to validate form before submitting


Hi Bill:

The best approach would be to use a custom validator.

http://msdn.microsoft.com/library/de...torcontrol.asp

This approach will work with the validation framework in ASP.NET and validate
the page client side (with script) before the form posts back to the server
(and validates on the server side as well).

--
Scott
http://www.OdeToCode.com/blogs/scott/
[color=blue]
> I need to validate a form to ensure that all of the fields add up
> correctly. I can't do this while the user is entering data since
> validation needs to be done after the entry is completed. What's the
> "best" way to validate prior to submitting?
>
> I could add an onsubmit attribute to the form which executes the
> validation in Javascript. That way the response doesn't need to be
> sent before validation takes place. Is this pretty much the way to do
> it?
>
> Thanks!
> Bill[/color]


IPGrunt
Guest
 
Posts: n/a
#3: Nov 19 '05

re: Ways to validate form before submitting


"Wysiwyg" <wysiwyg@xmissionNSPAM.com> confessed in news:ct6man$v5c$1
@news.xmission.com:
[color=blue]
> I need to validate a form to ensure that all of the fields add up[/color]
correctly.[color=blue]
> I can't do this while the user is entering data since validation needs to[/color]
be[color=blue]
> done after the entry is completed. What's the "best" way to validate prior
> to submitting?
>
> I could add an onsubmit attribute to the form which executes the validation
> in Javascript. That way the response doesn't need to be sent before
> validation takes place. Is this pretty much the way to do it?
>
> Thanks!
> Bill
>
>[/color]

Bill,

You could hook the onchange event in JS, but ASP.NET WebForms have built in
validation controls, meant to check existance, regular expressions, etc.

There is also a custom validator control designed for you to place your own
code, ie, to check for disallow characters, a particular input format, etc.

The ASP.NET framwork takes care of when to fire, and manages the flow of
control for you. All your validator has to do is set an IsValid field to true
or false.

Check this out. Very slick indeed!

-- ipgrunt
Wysiwyg
Guest
 
Posts: n/a
#4: Nov 19 '05

re: Ways to validate form before submitting


I'm already using all of those types of validation on individual fields.
When individual fields are updated the displayed subtotals update with
client code set up with the custom validators, the number ranges are
checked, etc. However, an onchange event doesn't help when I need to
evaluate the data after the user has finished entry. There's no point in
validating whether or not the data adds up if the user hasn't finished
entering it yet.

I need to validate the entire form right before it is submitted. I'm looking
for ways to validate the form as a whole and not individual fields.

Bill

"IPGrunt" <me@privacy.net> wrote in message
news:Xns95E9F200435B8swiss127army001wrenc@130.133. 1.4...[color=blue]
> "Wysiwyg" <wysiwyg@xmissionNSPAM.com> confessed in news:ct6man$v5c$1
> @news.xmission.com:
>[color=green]
> > I need to validate a form to ensure that all of the fields add up[/color]
> correctly.[color=green]
> > I can't do this while the user is entering data since validation needs[/color][/color]
to[color=blue]
> be[color=green]
> > done after the entry is completed. What's the "best" way to validate[/color][/color]
prior[color=blue][color=green]
> > to submitting?
> >
> > I could add an onsubmit attribute to the form which executes the[/color][/color]
validation[color=blue][color=green]
> > in Javascript. That way the response doesn't need to be sent before
> > validation takes place. Is this pretty much the way to do it?
> >
> > Thanks!
> > Bill
> >
> >[/color]
>
> Bill,
>
> You could hook the onchange event in JS, but ASP.NET WebForms have built[/color]
in[color=blue]
> validation controls, meant to check existance, regular expressions, etc.
>
> There is also a custom validator control designed for you to place your[/color]
own[color=blue]
> code, ie, to check for disallow characters, a particular input format,[/color]
etc.[color=blue]
>
> The ASP.NET framwork takes care of when to fire, and manages the flow of
> control for you. All your validator has to do is set an IsValid field to[/color]
true[color=blue]
> or false.
>
> Check this out. Very slick indeed!
>
> -- ipgrunt[/color]


IPGrunt
Guest
 
Posts: n/a
#5: Nov 19 '05

re: Ways to validate form before submitting


"Wysiwyg" <wysiwyg@xmissionNSPAM.com> confessed in news:ct8evp$89g$1
@news.xmission.com:
[color=blue]
> I'm already using all of those types of validation on individual fields.
> When individual fields are updated the displayed subtotals update with
> client code set up with the custom validators, the number ranges are
> checked, etc. However, an onchange event doesn't help when I need to
> evaluate the data after the user has finished entry. There's no point in
> validating whether or not the data adds up if the user hasn't finished
> entering it yet.
>
> I need to validate the entire form right before it is submitted. I'm[/color]
looking[color=blue]
> for ways to validate the form as a whole and not individual fields.
>
> Bill
>
> "IPGrunt" <me@privacy.net> wrote in message
> news:Xns95E9F200435B8swiss127army001wrenc@130.133. 1.4...[color=green]
>> "Wysiwyg" <wysiwyg@xmissionNSPAM.com> confessed in news:ct6man$v5c$1
>> @news.xmission.com:
>>[color=darkred]
>> > I need to validate a form to ensure that all of the fields add up[/color]
>> correctly.[color=darkred]
>> > I can't do this while the user is entering data since validation needs[/color][/color]
> to[color=green]
>> be[color=darkred]
>> > done after the entry is completed. What's the "best" way to validate[/color][/color]
> prior[color=green][color=darkred]
>> > to submitting?
>> >
>> > I could add an onsubmit attribute to the form which executes the[/color][/color]
> validation[color=green][color=darkred]
>> > in Javascript. That way the response doesn't need to be sent before
>> > validation takes place. Is this pretty much the way to do it?
>> >
>> > Thanks!
>> > Bill
>> >
>> >[/color]
>>
>> Bill,
>>
>> You could hook the onchange event in JS, but ASP.NET WebForms have built[/color]
> in[color=green]
>> validation controls, meant to check existance, regular expressions, etc.
>>
>> There is also a custom validator control designed for you to place your[/color]
> own[color=green]
>> code, ie, to check for disallow characters, a particular input format,[/color]
> etc.[color=green]
>>
>> The ASP.NET framwork takes care of when to fire, and manages the flow of
>> control for you. All your validator has to do is set an IsValid field to[/color]
> true[color=green]
>> or false.
>>
>> Check this out. Very slick indeed!
>>
>> -- ipgrunt[/color]
>
>
>[/color]

Thanks for explaining. I guess I missed an earlier question?

Anyway, you sound like you've thought about this and are on the right track
toward doing what's required.

BTW, there is a validator summary control. Perhaps there's an event you can
hook that makes sense for your need?

Good luck.

-- ipgrunt
Closed Thread