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

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