Lesson 12 - HTML forms

HTML forms are used to submit user input to a web service endpoint or other destination for further processing. HTML forms surround certain elements (outlined in the next lesson) and have the following basic structure:

See the Pen Basic HTML form structure by Curt (@curtsahd) on CodePen.

<form action="contact.php">

action – specifies the endpoint url to which the HTML form data should be submitted.

<input type="text" name="personName">

This is a standard text input element. The name attribute is necessary such that this input can be submitted to the action URL specified above. If the name attribute is omitted then the input element is not submitted to the endpoint URL.

<input type="submit" value="Submit">

This input element is the submit button which submits data contained within the form tags.

Form method

The method attribute can be added to the form tag to specify whether the form should be submitted using GET or POST. The default submission method of a form is GET should the method attribute be omitted.

GET

Form data is visible in the URL upon submission and submitted data is limited in terms of size.

POST

Form data is not visible in the URL and there is no size limitation on submitted data. POST is better suited to the submission of sensitive information.