If you want an alert it may be better to validate in javascript.
In your <form> tag you can use the "onsubmit" event to call a function. You then can have the function check fields. And if they are not valid generate an alert and "return false" to stop the form submission.
<script>
function check_form() {
if (!check_field(document.getElementById('name'))) return false;
}
function check_field(field) {
if (field.value.length < 8) {
alert('Please fill in all required fields');
field.focus;
return false;
}
else {
return true;
}
}
</script>
Obviously you can create much more complex validation code but it gives you the general idea.