• home
  • forum
  • my
  • kt
  • download
  • Basic Forms

    Author: 2007-07-31 17:18:23 From:

    Using simple HTML forms is a very slick way of receiving information from your visitors. You put a few boxes and buttons on your page, they enter in their details and you receive them through email ¡ª brilliant.

    This page was last updated on 2007-02-26


    Form Structure

    Just like the rest of HTML, forms follow a structure. The <form> tag is a container tag. It holds all of the elements, such as text boxes and submit buttons, which we¡¯ll see below, inside it. Our form container will look like this:

    <form name="feedback" method="post"  action="mailto:you@site.com">
    <!-- Form elements will go in here -->
    </form>

    This tag and its attributes start a new form; name the form ¡°feedback¡±, specify that the method the form will use is to post the information, and give the location that the information will be sent to with the action attribute ¡ª in this case your email address. Make sure you put your address in straight after the attribute, with no space in-between.

    Warning. This method of sending the data will just send an email, and in truth will not always work because of the different way some people will have set their email programs up. If you want a more robust solution which will also add a thank-you message afterwards, you need to use Perl or some other server-side scripting language to write a script that will send the email for you, which is a bit more complicated. For your first form, just send it straight to your email address.

    Once you¡¯ve set down that a form is going here, you will need to populate it with some of the input elements and a submit button. Put the parts below between the form tags.

    Text Boxes

    These will probably be the main parts of your form. They allow the reader to input either a line or multiple lines of text.

    One-line Text Box

    The first type of text box is a one-line box, suitable for information like their name or email address. It looks like this:

    Click inside the box and try it out. You can type anything you want. The code for one of these boxes is

    <input type="text" name="mail" size="25">

    <input>
    This is the tag name for many of the form elements that are there to collect user input.
    type
    The value of this attribute decides which of the input elements this one is. In this case, text is telling the browser that it¡¯s a single-line text-box.
    name
    When you get the results of this form in your email, you¡¯re going to need to know which responses were placed in which boxes, as you just get back a load of text. This is where the name attribute comes in. With this, each line in the response will be given a label in the email. If you used name="firstname", because you were using this box to find out the reader¡¯s first name, you would receive
    firstname=Ross
    in the email you are sent.
    size
    This specifies the length of the box on your page. If the box is not wide enough for the information that is entered, it will scroll across to allow more letters, but you should tailor this to the type of information being asked for so that most people can see their whole response at once.

    Text Area Box

    This box allows more than one line of text to be entered. It¡¯s suitable for comments, street addresses, that kind of thing. You don¡¯t need to press return at the end of each line, the browser will wrap the text automatically.