PHP Assignment 3

Using the form I showed in the week 3 videos (part 2), and the information you got about writing functions in part 1, here's what I want you to do:

  • Add a subject field to the Contact form.  This should be a select form element, with these options:
    • General question
    • Give me praise
    • Mean-spirited comment
    • Political comment
    • Meaning of Life
  • The subject the user selects should be used as the subject of the email (prefix it with "Website comment: ")
  • Before you send the email, first send the subject to a function that will test it.  You can call it "subject_validator".  If the subject is mean-spirited, or political, then this function should not allow the email to be sent.  You should show an error message - something like "I don't accept that kind of comment, sorry".
  • Also before you send the email, send the message of the email to another function.  You can call it "message_validator".  Strip out any malicious code using one or more built-in PHP functions (strip_tags is good).  If the message is longer than 60 characters, reject it with an error message. If the message has the word "scary" in it, then reject it also. 

Try to use an $error variable that is passed by reference to your functions, so you can collect and output the errors.  The functions should either return true/false, or return the error message (if you can't figure out pass by reference).

And last: Publish your homework up to a web server, so you can verify that it's sending out emails!

You'll need to zip up your code and send it to me via email so I can take a look..