form method='' - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:form

Introduction

The method attribute sets which HTTP method will be used to send the form data to the server.

The allowed values are get and post, which correspond to the HTTP GET and POST methods.

The default is is get.

To set the post value for the form in the example, as follows:

...
<form method="post" action="http://example.com/form">
...

Configuring the Data Encoding

The enctype attribute sets how the browser encodes and presents the data to the server.

There are three allowed values for this attribute listed in the following table.

Value
Description
application/x-www-form-urlencoded


default encoding. used when you don't apply
the enctype attribute. This encoding cannot be used to upload
files to the server.
multipart/form-data
This encoding is used to upload files to the server.
text/plain
This encoding varies between browsers.

The following form is used to show the difference for encodings.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
   <head> 
      <title>Example</title> 
   </head> 
   <body> 
      <form method="post" action="http://example.com/form"> 
         <input name="fave"> 
         <input name="name"> 
         <button>Submit Vote</button> 
      </form>  
   </body><!--  www .  j ava 2s.  co  m-->
</html>

The application/x-www-form-urlencoded Encoding

This is the default encoding.

It is suitable for every kind of form except those that upload files.

The name and value of each data item is encoded using the same scheme that is used to encode URLs.

Special characters are replaced with their HTML entity counterpart.

The name of the data item and the value are separated by the equals sign (=) and data/value tuples are separated by the ampersand character (&).

This is how the encoding is applied to the data in the example form:

fave=CSS&name=java2s.com+Jack

The multipart/form-data Encoding

The multipart/form-data encoding tends to be used only for forms that need to upload files.

The text/plain Encoding

The mainstream browsers encode data in different ways.

Google Chrome encodes data in the same way as for the application/x-www-form-urlencoded scheme, whereas Firefox encodes the data as follows:

fave=Apple

name=java2s.com

Related Tutorials