DEV Community

David Kanekanian
David Kanekanian

Posted on

E2 - Creating the Web Form

Open your index.php file (see Create project folder) and follow these steps:

1. Add an HTML html element and a body inside it.

<html><body></body></html>
Enter fullscreen mode Exit fullscreen mode

2. Add an HTML form element inside the body with blank action and method attributes (we’ll set them later).

<form action="" method=""></form>
Enter fullscreen mode Exit fullscreen mode

3. Add an HTML div element inside the form and add a label and an input element inside it for the first name field.

<div> <label>First Name:</label> <input name="first_name"> </div>
Enter fullscreen mode Exit fullscreen mode

4. Repeat step 3 for the last name field.

5. Add an HTML button element inside the form with inner text: submit.

<button>Submit</button>
Enter fullscreen mode Exit fullscreen mode

6. Try running the code. Notice it does nothing when submitted as the action and method aren’t set. Set the action to "process_my_form.php" and the method to "get" so we can process it in the next stage.

The final code should look something like this:

<html><body><form action="process_my_form.php" method="get">
    <div> <label>First Name:</label> <input name="first_name"> </div>
    <div> <label>Last Name:</label> <input name="last_name"> </div>
    <button>Submit</button>
</form></body></html>
Enter fullscreen mode Exit fullscreen mode

Parent topic: Example 2

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay