-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignUp.js
83 lines (70 loc) · 2.38 KB
/
SignUp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$(document).ready(function () {
$("form").submit(function (event) {
$(".form-group").removeClass("has-error");
$(".help-block").remove();
var formData = {
Fname: $("#Fname").val(),
Lname: $("#Lname").val(),
email: $("#email").val(),
password: $("#password").val(),
password2: $("#password2").val(),
phone: $("#phone").val(),
street: $("#street").val(),
city: $("#city").val(),
country: $("#country").val(),
};
// console.log(formData);
if (!isValidData(formData))
return;
else
$.ajax({
type: "POST",
url: "SignUp.php",
data: formData,
dataType: "json",
encode: true,
})
.done(function (data) {
// console.log(data);
if (!data.success) { // Error
// console.log(data);
} else { // Success
$("form").html('<script></script>' + '<div class="alert alert-success">' + data.message + "</div>");
window.location.href = 'homepage.html';
}
alert(data.message);
})
.fail(function (data) {
alert("AJAX FAIL !");
});
event.preventDefault();
});
});
function isValidData(formData) {
let valid = true;
if (formData["Fname"] === '' || formData["Lname"] === '') {
alert("Please Enter your Full Name");
valid = false;
}
if (formData["email"] === '') {
alert("Please Enter your Email");
valid = false;
}
if (formData["password"] === '') {
alert("Please Enter your Password");
valid = false;
}
if (formData["password2"] === '' || formData["password2"].localeCompare(formData["password"])) {
alert("Please Confirm your Password");
valid = false;
}
if (formData["phone"] === '' || isNaN(formData["phone"])) {
alert("Please Enter your Correct Phone Number");
valid = false;
}
if (formData["street"] === '' || formData["city"] === '' || formData["country"] === '') {
alert("Please Enter your Full Address");
valid = false;
}
return valid
}