var check; $(document).ready(function(){ var error =1; var message = ""; $('#txt_email, #txt_password, #txt_password2').keyup(function() { validateSignup(); }); $('#chk_terms, #chk_email').click(function() { validateSignup(); }); $('#txt_first').focus(); $('#txt_email2').bind("cut copy paste",function(e) { e.preventDefault(); }); function validateSignup(){ error = 0; if ($('#txt_first').val().length < 3) { error = 1; message = "Please enter your first name"; $('#txt_password').removeClass('borderGreenRight'); return; } if (!isValidEmail($('#txt_email').val())) { $('#txt_email').removeClass('borderGreenRight'); message = "Invalid Email Address"; error = 1; return; } else { $('#txt_email').addClass('borderGreenRight'); } if ($('#txt_email').val() != $('#txt_email2').val()) { $('#txt_email').removeClass('borderGreenRight'); $('#txt_email2').removeClass('borderGreenRight'); message = "Email addresses do not match"; error = 1; return; } else { $('#txt_email').addClass('borderGreenRight'); $('#txt_email2').addClass('borderGreenRight'); } if ($('#txt_password').val().length < 6) { error = 1; message = "Password must be at least 6 characters"; $('#txt_password').removeClass('borderGreenRight'); return; } else { $('#txt_password').addClass('borderGreenRight'); } if ($('#txt_password').val() != $('#txt_password2').val() || $('#txt_password').val().length < 6) { error = 1; message = "Passwords do not match"; $('#txt_password2').removeClass('borderGreenRight'); return; } else { $('#txt_password2').addClass('borderGreenRight'); } } $('#btnCreate').click(function(e){ e.preventDefault(); //$('#btnCreate').prop('disabled', 'disabled'); validateSignup(); if(error == "1"){ toastr["error"](message, "Invalid details"); return; } if (!$('#chk_terms').is(':checked')) { error = 1; toastr["error"]("Please accept the Terms and Conditions", "Problem with signup details"); return; } if (!$('#chk_email').is(':checked')) { error = 1; toastr["error"]("Please accept the email alerts", "Problem with signup details"); return; } $.ajax({ method:"POST", url:"/controllers/user/create_user.php", data:{ key: '', first: $('#txt_first').val(), last: $('#txt_last').val(), email: $('#txt_email').val(), password: $('#txt_password').val(), referrer: $('#referrer').val(), language_id: '16' }, dataType:"JSON", success: function(data) { if (data.error == 1) { toastr["error"](data.message, "Problem with signup details"); $('#btnCreate').prop('disabled', false); } else { $('#btnCreate').html(' Creating Account...'); $('#btnCreate').attr('disabled', 'disabled'); checkRequest(data.request_id); check = setTimeout(function(){ checkRequest(data.request_id); }, 2000) } } }); }); }); function checkRequest(request){ $.ajax({ url: 'controllers/user/create_check.php', type: 'POST', dataType: 'JSON', data:{ check:'check_request', request:request, email: $('#txt_email').val(), password: $('#txt_password').val() }, success: function (data) { if(data.error == 0){ if(data.is_complete == 1){ clearTimeout(check); window.location = '/overview.php'; } }else{ clearTimeout(check); swal({ type:'error', title:'Problem Creating Account', html:data.message }).then(function() { window.location.reload(); }) } } }); }