The <form> Tag
All input tags (checkboxes, radio buttons, text fields, etc.) must be contained within opening and closing
<form> tags. Any web page that accepts input from a user needs to have a form tag.
Use this form tag when publishing a form on www.bu.edu:
<form method="post" action="/htbin/ponyexpress2">
Use this form tag when publishing a form on people.bu.edu:
<form method="post" action="/cgi-bin/ponyexpress2">
In the majority of cases, it makes sense to nest the
<form> tags right inside the
<body> tags. This way, you can quickly check to make sure you’ve included the closing
</form> tag, and by listing certain special, hidden tags just after the opening
<form>, you can easily access these without wading through other HTML content. We’ll learn more about hidden tags when we discuss the PonyExpress program.
<form> tag requires two attributes: ACTION and METHOD. The ACTION specifies the program that the data will be sent to when the form is submitted — most forms on BU’s servers will use the PonyExpress URL for the ACTION.
The METHOD specifies how the data is sent. The biggest difference between the two commonly used methods, “get” and “post,” is that the “get” method sends the data encoded within a URL, and so can be seen in the browser’s location bar when the form is submitted, while the latter sends the data invisibly to the user as a large chunk of data. Since the “get” method is limited to 255 characters of data, you should generally use the “post” method.
You can have more than one form on a page, but you cannot have one form nested within another form. Two is uncommon and is potentially confusing to a user. If you need to have more than one form on a page, make sure the opening and closing form tags follow the syntax:
<form>...</form>...<form>...</form>. Also note that the information the user enters into the first form will not be submitted if the user clicks Submit within the second form and vice versa. For all of these reasons, we normally recommend having only a single form on a page.
When to use
Use the <form> tag whenever you have a form. Place the opening tag before any other of your form elements and place the closing form tag after any other of your form elements.