form submits before validation in php
<p>I have a form which I want to submit, so when I click on submit it goes to the selectorpage.php and finds the selected function type e.g. login in this, which further calls the controller to execute the function. Issue I have is that there is a function called validateForm() in js, as soon as I click the submit button, it goes to the selectorPage.php. I wanted to stop the form submission, perform validation through js and then submit the form from there, I used onsubmit = return false; in form tag but it just blocks the form of doing anything further. And I also don't know how to redirect the form to the selectorPage if it somehow works in js. So anybody would like to give me an idea how to submit form from js and then redirect that page to selectorPage.php. Thanks</p>

<pre><code>&lt;form method="post" action="selector.php?type=login" id="login" id="loginForm"&gt;
      &lt;div class="row"&gt;
           &lt;div class="offset1 span1"&gt;            
                &lt;div class="lbel"&gt;
                     &lt;label class="control-label" for "loginName"&gt;
                          Username/Email
                     &lt;/label&gt;
                &lt;/div&gt;
                &lt;div class="lbl_inpuCnt"&gt;
                      &lt;input type="text" class="input-xlarge" id="loginName"
                             name="loginName" maxlength="50"/&gt;
                &lt;/div&gt;
                &lt;div id="usernameError"&gt;&amp;nbsp;&lt;/div&gt;
                &lt;div class="lbel"&gt;
                      &lt;label class="control-label" for="loginPassword"&gt;
                             Password
                      &lt;/label&gt;
                &lt;/div&gt;
                &lt;div class="controls"&gt;
                       &lt;input type="password" class="input-xlarge" 
                               id="loginPassword" name="loginPassword" 
                                maxlength="50"/&gt;
                &lt;/div&gt;
                &lt;div id="passwordError"&gt;&amp;nbsp;&lt;/div&gt;&lt;br/&gt;
            &lt;/div&gt;
       &lt;/div&gt;
       &lt;div style="margin-left: 55px;"&gt;
           &lt;input class="btn" style="width: 80px;" type="reset" 
                    name="reset" value="Reset"/&gt;
           &lt;input class="btn" style="width: 80px;" type="submit" 
                    name="submit" value="Login" onclick="validateForm();"/&gt;
       &lt;/div&gt;
 &lt;/form&gt;
</code></pre>

<p>this is the javascript according to the code above</p>

<pre><code>function validateForm(){
    form = document.forms['loginForm'];
    if(document.getElementById('loginName').value == "")
        document.getElementById('usernameError').innerHTML = 'Invalid username or email';
    else{
        document.getElementById('usernameError').innerHTML = "&amp;nbsp";      
    form.submit();
    }
} //suppose it for the email validation only for the time being
</code></pre>
