0Pricing
PHP Academy · Lesson

Creating HTML Forms

Build forms for user input.

Creating HTML Forms is a free PHP Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the PHP Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Creating HTML Forms

Welcome to the next lesson! In this lesson, you’ll learn how to create forms using HTML. Forms are essential for collecting user input, which you can later process with PHP. Let’s get started!

Creating HTML Forms — illustration 1

2

What Are HTML Forms?

HTML forms are used to collect user input. They allow users to fill out fields, make selections, and submit data to a server for processing.

Example: A login form where users enter their username and password.

Key Point: Forms act as the bridge between the user and your PHP scripts.

3

Creating a Simple Form

Here’s how to create a basic HTML form:

Explanation:

  • action: Specifies the PHP file to handle the form data.
  • method: Specifies how to send data (GET or POST).
  • required: Ensures the field must be filled out before submission.
<form action="process.php" method="POST">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name" required>
  <button type="submit">Submit</button>
</form>

4

Form Elements

Forms can include various input types to collect different kinds of data:

  • text: For single-line text input.
  • email: For email addresses.
  • password: For password input.
  • checkbox: For multiple-choice selections.
  • radio: For single-choice selections.
  • submit: For submitting the form.

Example:

<form action="submit.php" method="POST">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required>
  <br>
  <label for="password">Password:</label>
  <input type="password" id="password" name="password" required>
  <br>
  <button type="submit">Login</button>
</form>

5

Using Radio Buttons

Radio buttons allow users to select one option from a group. Example:

Tip: Use the same name attribute for all radio buttons in a group.

<form action="submit.php" method="POST">
  <p>Choose your favorite color:</p>
  <input type="radio" id="red" name="color" value="Red">
  <label for="red">Red</label>
  <br>
  <input type="radio" id="blue" name="color" value="Blue">
  <label for="blue">Blue</label>
  <br>
  <button type="submit">Submit</button>
</form>

6

Using Checkboxes

Checkboxes allow users to select multiple options. Example:

Tip: Use an array syntax (hobbies[]) to collect multiple values.

<form action="submit.php" method="POST">
  <p>Select your hobbies:</p>
  <input type="checkbox" id="reading" name="hobbies[]" value="Reading">
  <label for="reading">Reading</label>
  <br>
  <input type="checkbox" id="traveling" name="hobbies[]" value="Traveling">
  <label for="traveling">Traveling</label>
  <br>
  <button type="submit">Submit</button>
</form>

7

Select Dropdowns

Dropdown menus allow users to choose one option from a list. Example:

Tip: Use selected to set a default option.

<form action="submit.php" method="POST">
  <label for="country">Choose your country:</label>
  <select id="country" name="country">
    <option value="USA">USA</option>
    <option value="Canada">Canada</option>
    <option value="UK">UK</option>
  </select>
  <br>
  <button type="submit">Submit</button>
</form>

8

Form Accessibility

Ensure your forms are accessible to all users:

  • Use label tags linked to inputs with for attributes.
  • Group related inputs using fieldset and legend.
  • Test forms for usability on mobile devices.

Tip: Accessible forms improve the user experience for everyone!

9

10

Great Job!

Congratulations! You’ve learned how to create HTML forms with various input types, including text fields, radio buttons, checkboxes, and dropdowns. Forms are the foundation of user input in web development. In the next lesson, we’ll learn how to process form data using PHP. Let’s keep coding!

Creating HTML Forms — illustration 10

Frequently asked questions

Is the “Creating HTML Forms” lesson free?

Yes — the full text of “Creating HTML Forms” is free to read here on the web, and the PHP Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the PHP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Creating HTML Forms”?

Build forms for user input. You practise PHP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start PHP Academy?

No prior experience is required. PHP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Creating HTML Forms” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this PHP Academy lesson?

Yes. Every PHP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Creating HTML Forms
  2. Handling Form Data with PHP
  3. Form Validation
← Back to PHP Academy