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 trialMarc Dimacuha
9,249 PointsUsing "required" values in input instead
I'm just wondering if creating an if statement to the top checking the values are filled out will be the same thing as typing the 'required' field in <input>?
What's the difference between:
if ($name == "" || $email == "" || $details == "") {
echo "Please fill in the required fields :
Name, Email and Details";
exit;
}
and:
<input type="text" id="name" name="name" value="" required>
Will it have more security measures since we're doing more code or will it serve the same purpose with 'required'?
2 Answers
Pontus Bolmér
12,471 PointsIt is the same as required. But if you are going to save the data in a database, there are some other checks that are a good thing to do, like htmlspecialchars.
Brandon Eichhorn
Courses Plus Student 2,035 PointsI made a small contact form for a client, I don't find it necessary, but I think it certainly would be a smart move just to include a PHP check as well.