I know this is not PHP but it's the best way if you want to make client-side validation with javascript. Form isn't submitted if validation fails.
<script language=javascript>
function check()
{
if (document.myform.name.value == "")
{
window.alert('you must fill name');
result = false;
return result;
}
}
</script>
<form action=2.html name=myform method=post onSubmit="return check();">
<input type=text name=name>
<input type=text name=phone>
<input type=submit name=sub>
</form>