spacer

A Simple Feedback Form

 
spacer
To compel the average web surfer —arguably one of the most demanding individuals on the face of the earth— to click on an email link, wait for their email program to open up, remember how the email program works and then send you an email is, in fact, a formidable task (Oh bother! My email program takes 7.2 seconds to load! You can't be serious!!)

Hence, as a matter of convenience (and to show everyone that you are above the cut by displaying some advanced web design skills) you might want to create a feedback form that visitors can use to send you an email directly from your contact page. The following is a crash course on how to create such a form.


An Example Form


Below is an example of a simple feedback form. The user types the appropriate information into the three text boxes and then clicks on the "Submit" button to send the data as an email to the designated recipient (you).


Your name:


Your email:


Your comments:




How This Form Works


What's going on behind the scenes can be roughly divided into two parts. The first part is the HTML source code that actually renders this form in a web page. In this source code, each of the three text input boxes is identified by a unique "control name".

The second part of the form is a form mail script (kind of like a little program) that is configured and placed in a special folder in your website's root directory called cgi-bin. When the user clicks on the Submit button, the form calls the form mail script into action. The form mail script uses the text box control names to collect and organize the information entered into the form and then sends it off as an email.

Most webmasters will only concern themselves with how to render the form using HTML source code and then afterward download and install a ready-made form mail script to process it. There are many free ready-made form mail scripts to be had out there on the internet. If you're looking for a quality open-source (free) form mail script, I personally recommend NMS FormMail. For more information, please see Installing NMS FormMail.



The Form Element


Okay so let's deal with the first part of our simple feedback form which is the HTML source code required to create it.

Creating forms starts with the form element which acts as a container for all the other special elements that are used to render various form components. The form element has a start tag <form> and an end tag </form> and has two important attributes, action and method, which are described below:
  • action ~ The value of the action attribute contains the URL to the script that will process the form (we'll get to that later...)
  • method ~ The value of the method attribute is either GET or POST. You will use one or the other depending on the requirements of the script processing the form. The method most commonly used is POST.
So far then, the HTML source code to our feedback form looks like this:


<form action="URL to form script" method="POST">
Other special elements go here...
</form>


To help with layout and presentation, the <form>...</form> tags may also contain most other HTML elements but, with the exception of <br> tags, we'll leave them out for now to keep this tutorial simple.



Text Boxes


Now let's create the text boxes used in our simple feedback form. The two HTML elements used to create text boxes (also known as text fields) are input and textarea. These are described below:
  • input ~ The input element will create a single-line text box when the type="text" attribute value pair is used. Only the start tag <input> is used. The end tag is omitted. You will also require a name="control_name" attribute-value pair where control_name equals the control name (whatever you want) that you assign to this text box. This control name will be used by the script that processes this form to retrieve the data entered into this text box. Each input text box must have a different control name.

    So if we insert the following code inside our form element:


    Your name:<br><input type="text" name="realname"><br><br>
    Your email:<br><input type="text" name="email">




    ...it will render the following result:

    Your name:


    Your email:

  • textarea ~ The textarea element creates a multi-line text box. It requires both a start tag <textarea> and an end tag </textarea> and the rows and cols attributes are used in the start tag to define its display size. These attributes are described below:

    • rows="number_of_lines" — This attribute-value pair specifies the height according to the number of text lines you wish the textarea box to display.
    • cols="width_in_characters" — This attribute-value pair specifies the width according to the number of character widths you wish textarea box to display.

    Also, like the input text boxes, we have to include the name="control_name" attribute-value pair where control_name equals the control name (whatever you want) that you assign to this text box. Hence if we insert the following code inside our form element:


    Your comments:<br>
    <textarea name="comments" rows="15" cols="50">
    </textarea>




    ...it will render the following result:

    Your comments:

    This textarea box is 15 text lines high and 50 character widths wide.



Submit Button


Now let's create a submit button that the user can click on to activate our simple feedback form after entering his or her information. Once again we'll use the input element but this time we'll insert the type="submit" attribute-value pair. To customize the text that is displayed on the submit button, you can use the value="your text" attribute-value pair where your text can be anything you want. To keep it simple (and polite) we'll just use the word "Submit". Hence if we insert the following code inside our form element :


<input type="submit" value="Submit">


...it will render the following result:




Putting It All Together


Alright then, if we take all the HTML source code for our form element, text boxes and submit button and put it all together, the following is what we get:


Your name:


Your email:


Your comments:


 


So all you have to do is whip up an essential web page structure (or use a web page that you've already created) and then insert the above source code anywhere in between the <body>...</body> tags and then presto...

You got yourself a simple feedback form.

For the purposes of the next tutorial on installing NMS FormMail, let's name this feedback form page "contact.htm".


*   *   *


Next, let's deal with the second part of our feedback form which is the script that will actually process the form when a user clicks on the Submit button...