DES 3005 - Web Design I

  DES 3005 - Web Design I

 

Week Eleven | Part Two

Setting up a Form

Now let's look at what's going on, piece by piece. Here's that code example again:

<form action="mailto:me@mywebsite.com" method="post"
enctype="text/plain" name="emailform" id="emailform">

The <form markup is the opening tag for our form. Naturally, when we've added all the other elements, we will complete our code with the closing tag </form>.

action="mailto:me@mywebsite.com"

This part looks a lot like those email links we created in the past, and it works the same way.

Emailing a form is just one of several actions you can code into a form. Another could include writing the information that is entered by to user to a database located on your server.

method="post"

This bit of code determines the way the form will be submitted. There are two methods:

  • GET, which passes information in a manner that can be seen by the user. This method is generally less secure.
  • POST, which sends date from the form within the body of the processing agent (e.g. your Web browser). This method is generally more secure and reliable.

The POST method will serve our purposes for this lecture and assignment.

enctype="text/plain"

The part of the tag tells the form how you want the data to be encoded. Whenever data is transmitted from one place to another, there needs to be an agreed upon means of representing that data. Since we want to receive (and read) an email from our visitor, we will encode the data as plain text.

The default value is "application/x-www-form-urlencoded", which is sufficient for almost any kind of form data.

The one exception is if you want to do file uploads. In that case, you should use "multipart/form-data".

name="emailform" id="emailform">

This last part provides the name of the form to the browser. Current W3C standards recommend the use of the id attribute in place of the name attribute. However, because of the way JavaScript was created, we can't be sure the form will be handled properly in all browsers. So, we'll cover all the bases by including both name and id properties with values in our email form.

 

Please go to Week Eleven Part 3 ».