..


Sponsored Links

Validating a form with ASP in a usable

Article written by Luca Ruggiero
Page 1 of 2

The methods of validation of data entered into a form that many are truly the best and what is really questionable, but there are some aspects that should be taken into account.

First is a good idea not just to control the client side but "deepen" the verification server side to prevent circumvention of controls by users with incorrect familiar with HTML.

Secondly, it is important that a form is usable, easily understandable for users in case of compilation errors.

More than once, unfortunately, I happened to run into form by the results "mysteries" like, "You made a mistake and the form has not been sent !"... unfortunate that the form in question (I do not do the site's name out of pure kindness) has about a dozen camps and I was not given any indication of the error made (reviewing all the data I have found to have committed a typo in the "Tax Code").

In this article, therefore, we will see an example of a form whose purpose vuol'essere more practical than teaching, in essence, I want to show how easy it is to create a server-side validation system clear and understandable to the user!

Specifically, our control will perform the following steps when the submit incorrect or incomplete information:

  1. will launch an error message on the side of the field is not filled or filled out wrong;
  2. fields will be filled in properly maintained (the relaivo field remains populated with the information you will not need to write them again);
  3. If successful in compiling the data will be processed and you will receive a clear confirmation message.
Here's an example of the form described above in action:
In this case, have been compiled only the fields for the name and the name, and address and the phone have an error message at compile time.

I should point out that the example given is not intended as a model on the validation data, but an example of how control processes can be managed in an intelligent way to help you understand the mistakes made and then to correct them.

So let's see the file form.asp, Article corrediamolo following code and run it on our personal Web server:






 <% @ LANGUAGE = VBScript%>







 <%



    



 Dim sending name, address, telephone



    



 send = Request.Form ("send")



    



 name = Request.Form ("name")



    



 name = Request.Form ("name")



    



 address = Request.Form ("address")



    



 telephone = Request.Form ("phone")



    



 Dim message, error



    



 error = 0



    



 message = "<span style=""color: #FF0000;""> Required </ span>"







 %>







 <html>



    



 <head>



        



 <title> control integrated in a form with ASP and cookies </ title>



        



 <style type="text/css">



        



 p, input



        



 {



            



 font: normal 12px verdana;



        



 }



        



 input



        



 {



            



 width: 250px;



        



 }



        



 </ Style>



    



 </ Head>







 <body>









 <form method="post" action="form.asp">



    



 <p>



        



 Name



        



 <%



            



 RU <> "" And name = "" Then



                



 Response.Write message



                



 error = error + 1



            



 End If



        



 %>



        



 <br> <input type = "text" name = "name" value ="<%= name%> ">



    



 </ P>



    



 <p>



        



 Surname



        



 <%



            



 RU <> "" And name = "" Then



                



 Response.Write message



                



 error = error + 1



            



 End If



        



 %>



        



 <br> <input type = "text" name = "name" value ="<%= name%> ">



    



 </ P>



    



 <p>



        



 Address



        



 <%



            



 RU <> "" And address = "" Then



                



 Response.Write message



                



 error = error + 1



            



 End If



        



 %>



        



 <br> <input type = "text" name = "address" value ="<%= address%> ">



    



 </ P>



    



 <p>



        



 Phone



        



 <%



            



 RU <> "" And phone = "" Then



                



 Response.Write message



                



 error = error + 1



            



 End If



        



 %>



        



 <br> <input type = "text" name = "phone" value ="<%= phone%> ">



    



 </ P>



    



 <p> <input type="submit" name="invio" value="Invio"> </ p>







 </ Form>









 <%



    



 RU <> "" And error = 0 Then



        



 With Response



            



 . Write "<p> 'just an example </ p>"



            



 . Write "<p>"



            



 . Write "</ p>"



        



 End With



    



 End If







 %>









 </ Body>







 </ Html>



Let us now examine the operation of the application in question.

In the same category ...
E-Learning
ASP (Advanced) ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €.
ASP Zero (Ebook) ASP Zero (Ebook)
Learning Microsoft ASP and VBScript from scratch. At only 29 €.
ASP and Access (Ebook) ASP and Access (Ebook)
Managing a MS Access database with ASP. At only 29 €.
Sponsored Links