
Marc Dimacuha
4,169 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
7,745 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
Pro 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.