Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created October 17, 2017 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/d346ad2a95da3e3f07b8123787ea14cf to your computer and use it in GitHub Desktop.
Save steveosoule/d346ad2a95da3e3f07b8123787ea14cf to your computer and use it in GitHub Desktop.
Miva - OCST Login AJAX
<div id="js-ocst-login" class="row mfp-hide forgot-password">
<form method="post" action="&mvte:urls:_self:auto;" autocomplete="off" class="column whole js-ocst-login-form">
<input type="hidden" name="Action" value="LOGN" />
<input type="hidden" name="Store_Code" value="&mvte:global:Store_Code;" />
<h4 class="fields-heading">Account Login:</h4>
<div class="form-row">
<div class="floating-placeholder">
<input type="text" name="Customer_Login" value="&mvte:global:Customer_Login;" id="l-Customer_Login" autocomplete="off" class="input">
<label for="l-Customer_Login">Email Address</label>
</div>
</div>
<div class="form-row">
<div class="floating-placeholder">
<input type="password" name="Customer_Password" id="l-Customer_Password" class="input">
<label for="l-Customer_Password">Password</label>
</div>
</div>
<div class="js-ocst-login-messages"></div>
<div class="row">
<div class="column whole medium-half">
<a href="&mvte:urls:FPWD:auto;" rel="nofollow" id="js-open-forgot-password" class="link">Forgot Password?</a>
</div>
<div class="column whole medium-half">
<button class="button button-block button-secondary white js-ocst-login-button">Login</button>
</div>
</div>
</form>
</div>
(function ocstLoginAJAX(){
$(document).on('submit', '.js-ocst-login-form', function(e){
e.preventDefault();
var $form = $(this),
$button = $form.find('.js-ocst-login-button');
if( $button.is(':disabled') ) return;
$button.prop('disabled', true).data('prev-text', $button.text() ).text('Processing...');
$('.js-ocst-login-messages').html('');
$.ajax({
url: $form.prop('action'),
type: $form.prop('method'),
dataType: 'html',
data: $form.serialize()
})
.done(function(response) {
var $response = $(response);
var $messages = $response.find('#messages');
if( $.trim($messages.text()).length ){
$('.js-ocst-login-messages').html( $messages.html() );
} else {
window.location.reload();
}
})
.always(function() {
$button.prop('disabled', false).text( $button.data('prev-text') );
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment