I see what you are doing, Javascript. My bad.
Well, if your code was all PHP, exit() is the escape function but in javascript, break and return false is the escape.
Unfortunatly, you can not escape your method because the page needs to render all to complete the javascript code. Use items such as the example below if this envolves a sql insert, update or delete.
if (isset($_POST['submit'])) {
if (empty($_POST['username'])) {
header("location: whatever.php?error=1"); exit;
} else {
// process
}
} else {
if ($_GET['error']==1) { echo "Sorry, you need to enter the username\n"; }
// page stuff here
}
Javascript escapes as follows
<script type="text/javascript">
function validate_form(form) {
if (form.field1.value == "" || form.field2.value == "") {
alert('All field are required ');
return false;
} else {
return true;
}
}
</script>