Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 202,528 times

Contents

Related Categories

Beginning Active Server Pages - Forms

Forms

Now you know the basics of ASP, we'll take a look at another aspect of Active Server Pages - collecting data. In HTML, any page that has a textbox or other form of input has a Form tag - even a Search engine uses forms. Once the fields have been filled in by the user, the information is 'posted' to another location. This can be a CGI script, compiled DLL, ASP Page, or simply an email address in the form of a mailto: link.

Before we set about dealing with the data that is sent to an ASP page, we need to know how to collect it. So, we'll have a quick look at the HTML tags required for a Form. First, you need a form tag. This tells the browser where to post the data, and how to do it:

<form action="mypage.asp" method="POST">
</form>

(Note that all the other form fields must be in between these two tags in order to be posted to mypage.asp. Next, you need to specify some fields. This most often done with an input tag (there are a few exceptions, but we won't deal with them here - take a look at the options in your HTML editor). The tag takes the form

<input type="InputType" name="FieldName" value="InitialValue">

InputType is usually Text - a text box, or Hidden - a field which is not displayed on the page. FieldName is a unique ID for this field. When retrieving the data after it has been posted, you need to know this FieldName value. InitialValue is the value of the field before the user makes any input (such as the Text property of a VB textbox).

Finally, you need a button or image for the user to click on to submit the data. This is usually in the form

<input type="submit" value="Button Caption">

If you want to use an image as the button, use

<input type="image" src="PathtoImage">

For our example, we're going to collect information for becoming a new member of our fictional site. To do this we're going to create single ASP page to collect the information, and then process it. For accessing data

First, add the following code to an ASP page named forminput.asp. At the moment, all it does is collect the data.

 <form action="forminput.asp" method="POST">
  Your Name <input type="text" maxlength=20 name="Name"><br>
  Your Email <input type="text" maxlength=100 name="Email"><br>
  <input type="hidden" name="Posted" value="1">
  <input type="submit" value="Sign Up">
 </form>

As you can see, first we include a form tag. Next, we include two text boxes for the Name and Email. We have set the input fields maxlength property, so we don't get any users trying to enter anything longer than we want. Next, we have a hidden field called 'posted' (this is explained later), and finally a submit button with its caption set to "Sign Up".

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [1010] Beginning Active Server Pages - absolute beginner!

    Posted by michael poxon on 16 Dec 2006

        Hi,
    When I say I'm an ASP beginner, I mean it! I've only written one trivial bit of code, and got a blank page. I see now that's described in the article snippet below. I did ind...

  • .I want to know how to save the files.whats the extensions...

    Posted by writetoksk on 04 Oct 2006

    hi,


    its first i started ASP.I want to know how to save the files.whats the extensions...Where can i get the sample programs

  • Posted by James Crowley on 28 Dec 2004

    Are you running IIS ? And are you viewing it in your browser via the correct URL? (ie something starting with http:// rather than file:// ) ?

  • Posted by James Crowley on 28 Dec 2004

    It does - you just can't see it ;) We've got an ISAPI filter that rewritse /show/1010/ to something like /show.aspx?id=1010

  • It's not working ;_;

    Posted by HyperHacker on 12 Dec 2004

    Is there something special I have to do besides saving it as a .asp file, or does it just not work on my server? It just spits out the code, even HTML, as plain text.

    [code]
    Let's see if ASP...