Pages

Tuesday, February 15, 2011

HTML Form Element


The form element is used to create a form in your document. The form element serves as a container in which various type of form controls is included, such as text field, check boxes, menus and buttons. The form element cannot be nested that means it cannot contain another form element inside it. You can have multiple forms but each form element should be separated from one another within a document.

Listed below are the most common attributes you can use for the form element:
  • action - provides the Uniform Resource Locator (URL) of the form handler of the form which is a script that will process the form data.
  • class - provides the class or classes of the heading. This attribute is used to identify the name of the style class or classes to be used for rendering.
  • enctype - provides the content type that is used to post the form. If the form includes file upload, the content type should be changed to "multipart/form-data" as the default value of this attribute is "application/x-www-form-urlencode".
  • id - provides a unique name for the form.
  • method - provides a value to specify what particular HTTP method is to be used when the form is submitted. The possible values are "get" and "post".
  • name - provides a name for the form.
  • style - provides a cascading style sheet (CSS) properties to the form.
  • title - provides a text title for the form. Most web browser displays the value of the title as a "tooltip".

Here's an example on how to use the form element:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
         <meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
         <mate name="keywords" content="blog, web development" />
         <title>the FORM element</title>
     </head>

     <body>
       <h1>
         the FORM element
       </h1>
       <form action="handler.php" method="post" id="frmNew" name="frmNew">
          <p>
              <label>Name:</label>&nbsp;
              <input type="text" name="txtName" id="txtName" value="" />
          </p>
          <input type="submit" name="btnSubmit" id="btnSubmit" value="submit" />
       </form>
    </body>
 </html>

0 comments:

Post a Comment