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
Seth Johnson15,199 Points
How does the one $error_message work for all "if" statements?
I'm struggling with a lot of what's happening in this video segment, but the main thing is:
How does the single $error_message variable generated by Alena in this section work for all of the different "if" conditionals?
My understanding is/was that there'd have to be unique variable names for each respective conditional; unless there's an exception here somewhere that I missed?
Is the answer simply that all of the previously-mentioned "if" conditionals are contained within the parent "if" conditional that checks/validates the request method near the beginning of the code?
Any advice/input would be greatly appreciated. :)
This is not an answer - I also am confused about the removal of the exit commands with each conditional. If the user did not put in the required fields, the error message variable is assigned a string. But then the code proceeds to check the other fields in sequence, so the last field with an error will populate the error message.
It seems like a waste to continue testing the fields after you know that one of the three required/mandatory fields has not been entered.