"use strict";
// Class definition
var KTSignupGeneral = function () {
// Elements
var form;
var submitButton;
var validator;
var passwordMeter;
// Handle form
var handleForm = function (e) {
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
validator = FormValidation.formValidation(
form,
{
fields: {
'k': {
validators: {
notEmpty: {
message: 'Kurum kodu gerekli'
}
}
},
'first-name': {
validators: {
notEmpty: {
message: 'Ad gerekli'
}
}
},
'last-name': {
validators: {
notEmpty: {
message: 'Soyad gerekli'
}
}
},
'email': {
validators: {
regexp: {
regexp: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
message: 'Girdiğiniz e-posta adresi geçerli değil',
},
notEmpty: {
message: 'E-Posta adresi gerekiyor'
}
}
},
'password': {
validators: {
notEmpty: {
message: 'Parola gerekiyor'
},
callback: {
message: 'Lütfen geçerli bir parola belirtin',
callback: function (input) {
if (input.value.length > 0) {
return validatePassword();
}
}
}
}
},
'confirm-password': {
validators: {
notEmpty: {
message: 'Parola doğrulaması gerekiyor'
},
identical: {
compare: function () {
return form.querySelector('[name="password"]').value;
},
message: 'Parola ve doğrulama parolası birbirinden farklı'
}
}
},
'toc': {
validators: {
notEmpty: {
message: 'Üyelik sözleşmesini kabul etmelisiniz.'
}
}
}
},
plugins: {
trigger: new FormValidation.plugins.Trigger({
event: {
password: false
}
}),
bootstrap: new FormValidation.plugins.Bootstrap5({
rowSelector: '.fv-row',
eleInvalidClass: '', // comment to enable invalid state icons
eleValidClass: '' // comment to enable valid state icons
})
}
}
);
// Handle form submit
submitButton.addEventListener('click', function (e) {
e.preventDefault();
validator.revalidateField('password');
validator.validate().then(function (status) {
if (status == 'Valid') {
// Show loading indication
submitButton.setAttribute('data-kt-indicator', 'on');
// Disable button to avoid multiple click
submitButton.disabled = true;
// Simulate ajax request
setTimeout(function() {
// Hide loading indication
submitButton.removeAttribute('data-kt-indicator');
// Enable button
$.post( "register.php", { k: form.querySelector('[name="k"]').value,first_name: form.querySelector('[name="first-name"]').value, last_name: form.querySelector('[name="last-name"]').value, email: form.querySelector('[name="email"]').value, password: form.querySelector('[name="password"]').value })
.done(function( data ) {
console.log(data);
submitButton.disabled = false;
if (data.success)
{
Swal.fire({
text: data.message,
icon: "success",
buttonsStyling: false,
confirmButtonText: "Tamam",
customClass: {
confirmButton: "btn btn-primary"
}
}).then(function (result) {
if (result.isConfirmed) {
form.querySelector('[name="password"]').value= "";
form.querySelector('[name="confirm-password"]').value= "";
passwordMeter.reset(); // reset password meter
//form.submit();
var redirectUrl = form.getAttribute('data-kt-redirect-url');
if (redirectUrl) {
location.href = redirectUrl;
}
}
});
}
else
{
Swal.fire({
text: data.message,
icon: "error",
buttonsStyling: false,
confirmButtonText: "Tamam",
customClass: {
confirmButton: "btn btn-primary"
}
})
}
});
return;
}, 1500);
} else {
// Show error popup. For more info check the plugin's official documentation: https://sweetalert2.github.io/
Swal.fire({
text: "Üzgünüm ancak bazı eksiklikler bulunuyor, lütfen eksiklikleri giderip tekrar deneyin.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Tamam",
customClass: {
confirmButton: "btn btn-primary"
}
});
}
});
});
// Handle password input
form.querySelector('input[name="password"]').addEventListener('input', function () {
if (this.value.length > 0) {
validator.updateFieldStatus('password', 'NotValidated');
}
});
}
// Password input validation
var validatePassword = function () {
return (passwordMeter.getScore() > 50);
}
var isValidUrl = function(url) {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}
// Public functions
return {
// Initialization
init: function () {
// Elements
form = document.querySelector('#kt_sign_up_form');
submitButton = document.querySelector('#kt_sign_up_submit');
passwordMeter = KTPasswordMeter.getInstance(form.querySelector('[data-kt-password-meter="true"]'));
if (isValidUrl(submitButton.closest('form').getAttribute('action'))) {
handleFormAjax();
} else {
handleForm();
}
}
};
}();
// On document ready
KTUtil.onDOMContentLoaded(function () {
KTSignupGeneral.init();
});