HTML Form Sample

By Xah Lee. Date: . Last updated: .

To generate a graphical user interface elements for input, such as buttons, menu, checkboxes, search box, message box, use a combination of:

HTML: Input Tag

HTML: Textarea Tag

HTML: Select Tag

Form Tag, Talking to Server

Note: the form tag is old technology, used around 1998 to 2000s, for sending input data to the server in a method called CGI script. Here's description of how it works.

Today, you use JavaScript to capture data and use JavaScript to talk to server. [see DOM Scripting Tutorial]

A form is done by the form tag. Like this:

<form action="" method="post" enctype="application/x-www-form-urlencoded">
<!-- input tags here -->

Between the opening/closing tag, should be GUI element tags such as {input, textarea, select, …}. These tags draws GUI elements such as {menu, radio button, button, text field, …}.

When user click on the submit button, the data is sent back to the script action="" on server.

When a form is submitted, a list of name/value pairs is generated as input to the script.

The value may be a number, a string, or a list if the GUI element is a multiple-result one such as check boxes and multi-selection menu.

The following are GUI elements you can use. Each one has a “name” and “value” attributes. The value of “name” attribute is the name of variable sent to your CGI script, and the value of “value” attribute is a string displayed in browser as the default value/choice.

see also HTTP Protocol Tutorial

Uploading a file

Send this file:

HTML code:

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="xyz.php" method="POST">
  <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000">
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file">
    <input type="submit" value="Send File">
Liket it? I spend 2 years writing this tutorial. Help me spread it. Tell your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Object Ref
  5. DOM Scripting
  6. SVG
  7. Blog