I've set up my code so that it would require all the fields within the form, but for some reason it's only applying to input types of text, email, and password. So my question is how can I get the radio buttons, select boxes, and checkbox to also be required fields within the form? Here's my code:
<form action="" method="post">
<ul id="register">
<li>
<input type="text" name="first_name" placeholder="First Name">
</li>
<li>
<input type="text" name="last_name" placeholder="Last Name">
</li>
<li>
<input type="email" name="email" placeholder="Email"><br><br>
</li>
<li>
<input type="password" name="password" placeholder="Password">
</li>
<li>
<input type="radio" name="sex" value="male">Male
<input type="radio" name="sex" value="female">Female
</li>
<li>
Birthday:
<select name="month">
<option value="January">January</option>
//all the other month options
</select>
<select name="day">
<option value="1">1</option>
//all the other days of the month
</select>
<select name="year">
<option value="2013">2013</option>
//ton of year options here
</select><br><br>
</li>
<li>
<input type="checkbox" name="terms_of_service" value="termsofservice">Terms of Service<br><br>
</li>
<li>
<input type="submit" name="registrationform" value="Sign up">
</li>
</ul>
</form>
<?php
if (empty($_POST) === false) {
$required_fields = array('first_name', 'last_name', 'email', 'password', 'sex', 'birthday', 'terms_of_service');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'You didn\'t fill in all of the categories.';
break 1;
}
}
}
print_r($errors);
?>