Basic Web Page with a Form

Concepts

This page is as small and concise as I could manage while still showing an example or two of all the following:

I have several examples of CSS rules in here, one to format the DIV that wraps the whole page and one to format the form.

Forms

This page also has a form. Forms are crucial in CS 304, because they allow us to collect information from the user, whether a FaceBook post, an item to offer on eBay, or a review of an Amazon purchase.

Forms have to have the following:

Some controls can be marked required by adding that attribute. Modern browsers will prevent the form from being submitted if any required control has an empty value (the empty string). For many elements, such as input, that's all you need. For select, you need to ensure that the default menu choice (option) has a value that is the empty string. For textarea, the default value is the text between the beginning tag and the ending tag, so you need to snug them up right next to each other to make it the empty string (not even a single space is allowed).

In this example form, every control is required, so you can see this in action. Try it!

When the form is submitted, the data goes to the server (Apache), which directs it to the script, and the script outputs a response, which the browser uses to replace the current page.

In this example form, the echo responses with the information sent by the form, the collection of control names and values. Try it!