Implement Mad Libs in PHP, with a very simple interface.
The first page the user will be presented with is a simple greeting and a form with the following:
- An entry (text box) prompting for the users name
- Multiple entries / textboxes prompting for the various parts of speech/words for the user to enter
- A submit button.
Upon pressing the submit button, the user will sent to another page to be presented with her story as well as a link to the url of the text version of the story which has been saved. A link to "start-over" should also be included.
In addition to the above, the first page will also include an "I'm lazy" button. If "I'm lazy" is pressed instead of "submit" — the user will be presented with a generated story, wherein the parts of speech will be randomly selected from a list. The option to save should still be there.
Notes: There's stil a LOT to think about, despite these relatively simple instructions. Additional things:
- There are a LOT of different ways to get the random words. You could try an approach based on the bash one (sorting and pulling a line), or just google around and see what "random line from file" gets you. In case you still need the wordlists, which you'll probably want to transfer over, they're downloadable from the following old page (again, newcomers, this was from an older assignment)
FSU Courses:LIS5364:Assignment 2 - Advanced Bash:hints3
- We haven't gotten to it much yet, but sanitizing inputs (making sure the user doesn't try to hack you by inserting code instead of data) is pretty important, and you should do it here.
A good minimum — which would be annoying but aggressively safe is to simply reject the entire thing and force the user to start over if anything other than alphanumeric content is recieved. A function would be very good for this. In the final project from last time, you could simply assign the value "recieved" into the POST variable without error checking; what you will want to do now is only *conditionally* assign the value — one way would be to assign the true value if the input is valid, otherwise assign some sort of "ERROR" if the input is invalid. Then, on the next page, conditionally "run" the generator if the input is valid — or show the user an error and invite them to start over. You could simply make lots of pages with links for this, or you could try some cleverness using ISSET type variables with POST.
This may help (as well as any other PHP function or stack overflow help you can find) :
- Also, opening and saving files is correctly much more of a pain, for good reason. Here is some help.
- There are a *ton* of little user interface issues and ideas you could think about here, having to do with control flow and such. One advanced idea might be: Instead of jumping straight to the page, it's possible to actually have the form autofill itself with the random words before jumping to the next page. The user could, at that point, approve and print the story, or "roll the dice" again.
Offhand, these were the issues that I feel like would be the most important. Definitely feel free to barrage me with questions, and I will send announcements if I make major changes, additions here.