HTML Form Tag
Description
Forms are used to accept used entered data and then pass that data to and from a server.
Forms cannot be nested. But you can have more than one form in a page.
Examples
Form POST Examples
PHP Post Example:
<form action="form_results.php" method="POST">
<input type="text" id="txtTextBox" value="hithere" />
<input type="submit" id="submit" />
</form>
form_results.php:
<?php
echo $_POST['txtTextBox'];
?>
ASP Post Example:
<form action="form_results.asp" method="POST">
<input type="text" id="txtTextBox" value="hithere" />
<input type="submit" id="submit" />
</form>
form_results.asp:
<%
Dim strTextBox
strTextBox = Request.Form("txtTextBox")
Response.Write(strTextBox)
%>
Form GET Examples
PHP GET Example:
<form action="form_results.php" method="GET">
<input type="text" id="txtTextBox" value="hithere" />
<input type="submit" id="submit" />
</form>
form_results.php:
<?php
echo $_GET['txtTextBox'];
?>
ASP GET Example:
<form action="form_results.asp" method="GET">
<input type="text" id="txtTextBox" value="hithere" />
<input type="submit" id="submit" />
</form>
form_results.asp:
<%
Dim strTextBox
strTextBox = Request.QueryString("txtTextBox")
Response.Write(strTextBox)
%>
Attributes for <form>
| action |
a url e.g. http://servername.domain.com/webpage.php |
the URL of the application that will receive and process the form data entered by the user.
The url would point to a server side script file e.g. a php, jsp, aspx file |
| enctype |
application/x-form-urlencoded - default
|
specifies how the browser encodes the form data for submission to the server. |
| method |
post
get (default value) |
The HTTP method to use to submit the form data to the server.
Get places the form data in the url by appending name value pairs
Post puts the form data in the body of the HTTP request. |