There is almost no website that does not have a form on at least one of its pages. Forms are useful for gathering information from website visitors and users. A form processing script must get the form data after the user submits it to the server, verify that the user input fits the intended format for each field (e.g., the email address field must be a string of text in the format of a valid email address), and process the information as required. The script could save it to a folder, send it via email, or simply process it and show the results. Validating user feedback is critical for preventing malicious users from wreaking havoc on your website.
The form tag is used to define a form in HTML, and it is followed by the /form tag. This tag may have a variety of attributes, such as method (GET or POST) and behavior (the url of the form processing script). The type data is encoded in the action URL while using the GET process. When the form is a query form, this approach is suggested. The form data should appear inside the message body when using the POST process. When the form will be used to update a database, send email, or perform some action other than retrieving data, this is the preferred way.
The data is collected using the form fields. Each field is usually labeled so that the user knows what data to enter. There are various types of fields, including:
- Multi select
- Radio buttons
The hidden fields are used to submit data along with the form that the user does not need to see. A form number, for example, could be used to identify which form has been submitted by the form processing script.
Users can upload a file using the File field. The file will be combined with the rest of the form data by the form processing script. You must have this attribute in the form tag for this field to function properly: enctype=multipart/form-data.
The submit and reset buttons are used to submit and reset the form.
For a complete summary of each tag’s attributes and syntax, consult an HTML guide. Among several other pages, you can find a guide at http://www.w3schools.com/tags/default.asp or http://www.w3.org/MarkUp/.
When the form is complex, the fieldset tag may be used to group fields into areas. Place the fieldset tag, then the legend Section Name /legend tag, then all of the relevant type fields, and finally the /fieldset tag.
To adjust the appearance of the type controls, you can use CSS (Cascading Style Sheets) or inline styles.