Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Michael Pashkov
Michael Pashkov
22,024 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>