Lecture

Form Tag

A form in a web page is used to collect information and submit the collected data to a server.

For example, when signing up, a form can be used to input a name, email address, and password, then send the entered data to a server.


Basic Form Structure
<form action="" method=""> <!-- Various elements for user input will be inserted here --> <input type="text" name="username" placeholder="Enter your name" /> </form>
  • action: Represents the URL of the server where the form data will be sent.

  • method: Determines how to send the form data to the server. "GET" and "POST" are commonly used; "GET" appends data to the URL, whereas "POST" sends data in a hidden way.


Input Elements

A form can contain various input elements such as text fields, radio buttons, and checkboxes.

It's similar to composing an exam paper with different types of questions (multiple-choice, short answer, etc.).


Text Input

A text input field can be created using the <input> tag. It's akin to answering short answer questions on an exam paper.

Text Input Field
<input type="text" name="username" placeholder="Enter your name" />
  • type: Specifies the type of input, where "text" indicates regular text.

  • name: Acts as the key for data sent to the server, much like question numbers on an answer sheet.

  • placeholder: Displays text when the input field is empty, guiding the user on what to input.


Button

A form submission button is created with the <button> tag.

Submit Data with a Button
<button type="submit">Submit</button>

Checkbox and Radio Button

Checkboxes are created with <input type="checkbox">, and radio buttons with <input type="radio">.

Checkboxes are used for multiple selections, like a question that asks 'Select all that apply,' whereas radio buttons are for single selections, much like a multiple-choice question.

Checkbox and Radio Button
<input type="checkbox" name="hobby" value="reading" /> Reading <input type="radio" name="gender" value="male" /> Male
Mission
0 / 1

The method attribute of the form tag is primarily used with GET or POST methods.

True
False

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

HTML
CSS
Loading...