Skip to content

Instantly share code, notes, and snippets.

@putheakhem
Created May 23, 2025 04:08
Show Gist options
  • Save putheakhem/ef2f29e5ed8c0b05b55f692c9e16123e to your computer and use it in GitHub Desktop.
Save putheakhem/ef2f29e5ed8c0b05b55f692c9e16123e to your computer and use it in GitHub Desktop.

πŸ“ HTML Form Exercise

🎯 Learning Outcomes

By completing this exercise, students will be able to:

  • Understand basic form elements: <form>, <input>, <textarea>, <select>, <button>
  • Set name, type, placeholder, and value attributes correctly
  • Use form submission with the action and method attributes
  • Group fields using <fieldset> and <legend>

🧩 Part A – Create a Simple Contact Form

Instructions:

  1. Create an HTML file named contact-form.html.
  2. Create a form that includes the following inputs:
  • Full Name – Text input
  • Email Address – Email input
  • Message – Textarea with 5 rows
  • Submit – Button
  1. Set the action="#" and method="post" attributes in the <form> tag.
  2. Add appropriate placeholders and labels.

πŸ“¦ Part B – Add More Input Types

Instructions: Create another form section that includes:

  • Date of Birth – type="date"
  • Gender – Radio buttons (Male, Female, Other)
  • Subscribe to Newsletter – Checkbox
  • Password – type="password"
  • Confirm Password – type="password"

πŸŽ›οΈ Part C – Use a Select Dropdown

Instructions: Add a dropdown (<select>) for selecting your Country, with the following options:

  • Cambodia
  • Thailand
  • Vietnam
  • Laos

Label this field properly and make it required.


πŸ“š Part D – Group Your Form with <fieldset>

Instructions: Group related fields using <fieldset> and <legend>. For example:

  • Contact Info
  • Account Info

🧠 Challenge Task – Create a Registration Form

Design a full registration form including:

  • Name

  • Email

  • Phone Number

  • Country (dropdown)

  • Gender (radio)

  • Newsletter (checkbox)

  • Password and Confirm Password

  • Use placeholders, labels, and required fields

  • Include a Reset button

  • Use CSS to style the form nicely (optional)


πŸ§ͺ Optional Bonus

Add validation rules:

  • Email should be in email format
  • Password and Confirm Password must match
  • All required fields must be filled

πŸ“š Reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment