Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Enhancing a Simple PHP Application Integrating Validation Errors Setting an Error Message Variable

error message

quick question. why did you use:

<?php !isset($error_message) instead of isset($error_message) ?> ?

If the message is not set then why would you want to run the error message? I'm confuse...

<?php if (!isset($error_message) && $_POST["address"] != "") { $error_message = "Your form submission has an error."; } ?>

1 Answer

Joe,

Im not looking at the code right now but I can say from experience this type of conditional is used to catch an extra scenario. (If I remember right Randy goes back and uses if(empty))

<?php

//Basically it works like this:
if(!isset($error) && $_POST['address'] !=""){
$error = "Error"

This reads as: If the Error Message is NOT set and the Address field is NOT blank then theres an error.

This is a security check. The address field is a hidden field a person could not edit. But a machine edits code in a different way to send spam. Thus if the address field was populated, and there is not already an error we certainly need to set one.

This is an old school way of doing this without CAPTCHA's and really Randy is showing us a method here that shows his intelligence, CAPTCHA's are irritating, this is painless on the user.