Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Adding a Basic Form Creating Input Fields

Michael Pashkov
Michael Pashkov
22,023 Points

I did not understand why we did HTML form with table inside. What for?

<form method="post" action="process.php">
            <table>
            <tr>
                <th><label for="name">Name</label></th>
                <td><input type="text" id="name" name="name" /></td>
            </tr>
            <tr>
                <th><label for="email">Email</label></th>
                <td><input type="text" id="email" name="email" /></td>
            </tr>
            <tr>
                <th><label for="details">Suggest Item Details</label></th>
                <td><textarea name="details" id="details"></textarea></td>
            </tr>
            </table>
            <input type="submit" value="Send" />
        </form>

1 Answer

Moosa Bonomali
Moosa Bonomali
6,297 Points

After viewing the html in a browser, you will notice the Form elements are arranged in a nice tabular way and this is the effect the author wanted to get. There are other ways of displaying Form elements on a webpage and the author happened to choose this one. You could use a bunch of DIV to achieve the same effect or a different effect altogether. Most would also include some CSS to achieve a desired effect. Take a look at the output of the following code with just Form elements and you will realize the output is uninteresting you need to do some tinkering to get the effect your desire;

<form method="post" action="process.php">
    <label for="name">Name</label>
    <input type="text" id="name" name="name" />
    <label for="email">Email</label>
    <input type="text" id="email" name="email" />
    <label for="details">Suggest Item Details</label>
    <textarea name="details" id="details"></textarea>
    <input type="submit" value="Send" />
</form>