PHP: Hot Pages: Your Favorite Color
- Basic Code
- PHP: Hot Pages
- A Poll
- Your Favorite Color: Classes
- Once you start getting into more complex code, you’ll have a lot of variables and functions. You might imagine have one variable for the current time, and then in another separate part of your page having a variable for the time that an event starts, and elsewhere a variable storing the amount of time left until some event happens. It’s not unlikely that with all that complexity you’ll end up calling different values by the same name, creating…
- Simple form
- Let’s create a page to ask people their favorite color. The basic page is in the resources as “color.php”.
- Cleaning your data
- I say this several times throughout this tutorial: you cannot trust the data that comes in from browsers. You don’t know who is submitting, you don’t know why they’re submitting, and you don’t know how they’re submitting. You only know what they’re submitting if you make no assumptions about it.
- Your Favorite Color: Email
- One common means of collecting form data is to email it to yourself. If you don’t get many form responses and don’t need to collect that data into a database, this is a quick and simple means of accepting form responses.
- Post and Get
- There are several “methods” that you can use to send your form data to the server for PHP to parse. Two of the most common are “post” and “get”. The get method is very useful if you want your visitors to be able to come back to the results page. For example, if your form searches rooms in a building, you might use get to allow them to bookmark a specific building. Or if you are providing a form that lets them search a list of classes by topic,…
- The final code
- The final code in Your Favorite Color