dpDesignz
dpDesignz

Reputation: 1959

.submit() not firing on form

I have the following form

<form action="" method="post" name="loginForm" id="loginForm">
    <div id="spinnerInsert">
        <div class="form-content"><input type="text" name="loginUser" id="loginUser" class="validate[required,minSize[3]]" required /><span class="form_highlight"></span><span class="form_bar"></span><label for="loginUser">Username</label><span class="form_hint">Enter your username here</span></div>
        <div class="form-content"><input type="password" name="loginPassword" id="loginPassword" class="validate[required]" required /><span class="form_highlight"></span><span class="form_bar"></span><label for="loginPassword">Password</label><span class="form_hint">Enter your password here</span></div>
    </div>
    <div class="form-content buttons"><p><input name="action-login" type="submit" id="action-login" value="Sign In" class="button confirm" style="width: 140px;" /><br/><a href="">Register</a> &middot; <a href="">Forgot Password</a></p></div>
</form>

and then the following code in the script

$('form#loginForm').submit(function(event) {
    // Get data and submit
    $('#spinnerInsert').spin();
    $.getJSON("lib/class/class.login.php", {loginUser: $('input#loginUser').val(), loginPassword: $('input#loginPassword').val(), queryType: "1"})
    .done(function(response) {
        $('#spinnerInsert').spin(false);
        if(response.success===0){
            // Show Error
            toastr.error(response.message, 'Error');
            // If totalFails > 4, lock account and offer to reset password or email admin
            if(response.totalFails>4) {
                $('article#pageForm').html('<p id="accountLocked">Sorry, your account has been locked. Please <a href="">reset your password</a> or <a href="mailto:adminemail">contact the site admin</a> to unlock your account</p><p><a href="javascript:backToLogin();">Back to Sign In</a></p>');
            }
        } else {
            // Load Authentication Section
            $('article#pageForm').html(response.data);
        }
    });
    event.preventDefault();
    return false;
});

But for some reason every time I press submit it just reloads the page. It doesn't trigger my script at all.

It was working yesterday, but isn't today, and I don't remember changing anything.

I've tried $(document).on('submit','form#loginForm',function(event) { as well.

Full demo at http://spendit.dpdesignz.co/

Upvotes: 0

Views: 126

Answers (1)

Nirmalya Ghosh
Nirmalya Ghosh

Reputation: 2530

The problem is that .spin() is not defined. Try removing those lines which contain .spin() and try submitting your form.

$('form#loginForm').submit(function(event) {
    // Get data and submit
    $.getJSON("lib/class/class.login.php", {loginUser: $('input#loginUser').val(), loginPassword: $('input#loginPassword').val(), queryType: "1"})
    .done(function(response) {
        if(response.success===0){
            // Show Error
            toastr.error(response.message, 'Error');
            // If totalFails > 4, lock account and offer to reset password or email admin
            if(response.totalFails>4) {
                $('article#pageForm').html('<p id="accountLocked">Sorry, your account has been locked. Please <a href="">reset your password</a> or <a href="mailto:adminemail">contact the site admin</a> to unlock your account</p><p><a href="javascript:backToLogin();">Back to Sign In</a></p>');
            }
        } else {
            // Load Authentication Section
            $('article#pageForm').html(response.data);
        }
    });
    event.preventDefault();
    return false;
});

Upvotes: 1

Related Questions