如何在失败的javascript验证时运行php脚本?

I have a simple html signup form with onsubmit = "return validateForm()" where validateForm() is javascript to ensure input is in the correct form and e-mail and password fields match their confirm fields.

The forms action is set to add.php. add.php adds the input into a mysql database. Both the javascript and php work fine, however even when javascript alerts an error such as "password too short." the php script is run anyways and a new entry made in the database.

I would like the php script to only run upon successful javascript validation, and the user to remain on the same page if any validation fails, how is this done?

I can add code if needed but I think the answer here would be generic.

EDIT:

for example here is the code for validating name fields:

function checkName()
{
    var fName = document.getElementById("firstName");
    var lName = document.getElementById("lastName");
    if (fName.value.length >= 2 && fName.value.match(/^[A-Za-z]+$/) && lName.value.length >= 2 && lName.value.match(/^[A-Za-z]+$/))
        {
            return true;
        }
    else
        {
            return false;
        }
}

function validateForm(){
if (checkName() == false)
        {
            alert("First and Last Name must be at least 2 characters long and contain  only alphabetic characters");
        document.getElementById("fName").focus();
        document.getElementById("fName").select();
        return false;
    }

}

Is it firstName or fName? If the fName ID doesn't exist, the function will hit an error and exit without returning anything, causing the alert to show, but the form to still submit.