<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simple Form</title>
</head>
<body>
<h1>Contact Us</h1>
<!-- The 'action' attribute specifies where the form data will be sent -->
<!-- The 'method' attribute specifies the HTTP method to be used (GET or POST) -->
<form action="/submit_form" method="post">
<!-- Text Input -->
<label for="name">Name:</label>
<input
type="text"
id="name"
name="user_name"
placeholder="Your name"
required
/>
<br />
<!-- Email Input -->
<label for="email">Email:</label>
<input
type="email"
id="email"
name="user_email"
placeholder="Your email"
required
/>
<br />
<!-- Password Input -->
<label for="password">Password:</label>
<input type="password" id="password" name="user_password" required />
<br />
<!-- Radio Buttons -->
<p>Preferred Contact Method:</p>
<input
type="radio"
id="contact_email"
name="contact_method"
value="email"
checked
/>
<label for="contact_email">Email</label>
<input
type="radio"
id="contact_phone"
name="contact_method"
value="phone"
/>
<label for="contact_phone">Phone</label>
<br />
<!-- Checkbox -->
<input type="checkbox" id="subscribe" name="subscribe" checked />
<label for="subscribe">Subscribe to our newsletter</label>
<br />
<!-- Textarea for Longer Text -->
<label for="message">Message:</label>
<textarea
id="message"
name="user_message"
rows="4"
cols="50"
placeholder="Your message"
></textarea>
<br />
<!-- Submit Button -->
<input type="submit" value="Submit" />
</form>
</body>
</html>
-
<form>
element: This is the container for your form. Theaction
attribute specifies the URL where the form data will be sent, and themethod
attribute specifies the HTTP method (usually “GET” or “POST”). -
Text Input (
<input type="text">
): Used for single-line text input. Theid
attribute is a unique identifier, and thename
attribute is the key that will be used to identify this field when the form is submitted. -
Email Input (
<input type="email">
): Similar to text input but specifically designed for email addresses. -
Password Input (
<input type="password">
): Used for password input. The text is usually masked for security. -
Radio Buttons (
<input type="radio">
): Used when the user must select one option from a group of options. Thename
attribute groups the radio buttons together. -
Checkbox (
<input type="checkbox">
): Allows the user to select multiple options. Thechecked
attribute makes the checkbox initially selected. -
Textarea (
<textarea>
): Used for multi-line text input, suitable for longer messages. -
Submit Button (
<input type="submit">
): Submits the form when clicked.