-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathregistration.php
164 lines (143 loc) · 6.45 KB
/
registration.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
session_start();
include "includes/db.php";
include "includes/header.php";
?>
<link href="css/form_style.css" rel="stylesheet">
<!-- Navigation -->
<?php include "includes/navigation.php"; ?>
<!-- Page Content -->
<div class="background">
<div class="container1">
<div class="screen">
<div class="screen-header">
<div class="screen-header-left">
<div class="screen-header-button maximize"></div>
<div class="screen-header-button minimize"></div>
<div class="screen-header-button close1"></div>
</div>
<div class="screen-header-right">
<div class="screen-header-ellipsis"></div>
<div class="screen-header-ellipsis"></div>
<div class="screen-header-ellipsis"></div>
</div>
</div>
<div class="screen-body">
<div class="screen-body-item left">
<div class="app-title">
<span>REGISTER</span>
<span> Blogger</span>
</div>
<div class="app-contact">Always there to help you</div>
</div>
<div class="screen-body-item">
<div class="app-form">
<div class="head">
<form role="form" method="post" id="regis-form" autocomplete="off" onsubmit="validate_form()">
<div class="app-form-group">
<label for="fullname" style="color: white;">Full Name</label>
<input type="text" name="fullname" id="fullname" class="app-form-control" placeholder="Enter Your Name ">
</div>
<div class="app-form-group">
<input type="hidden" name="contact_number">
<label for="name" style="color: white;">Username</label>
<input type="text" name="username" id="username" class="app-form-control" placeholder="Unique username">
</div>
<div class="app-form-group">
<label for="name" style="color: white;">Email</label>
<input type="email" name="email" id="email" class="app-form-control" placeholder="Email">
</div>
<div class="app-form-group">
<label for="name" style="color: white;">Password</label>
<input type="password" name="password" id="key" class="app-form-control" placeholder="Password">
</div>
<div class="app-form-group buttons">
<input class="app-form-button" id="reset" value="Reset" type="button" name="reset" onclick="clearForm()">
<input type="submit" name="submit" id="btn-login" value="Register" class="app-form-button">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/emailjs-com@2/dist/email.min.js'></script>
<script type='text/javascript'>
// Initiate Email JS
(function() {
emailjs.init('user_ctUkVZSQhl8tJdwn5OV7N');
})();
// Reset the form
function clearForm() {
document.getElementById('username').value = "";
document.getElementById('email').value = "";
document.getElementById('key').value = "";
document.getElementById('fullname').value = "";
}
// display alert message
function showAlert(alertMsg, alertType) {
const card = document.querySelector('.app-form');
const head = document.querySelector('.head');
const errordiv = document.createElement('div');
errordiv.className = alertType;
errordiv.appendChild(document.createTextNode(alertMsg));
card.insertBefore(errordiv, head);
setTimeout(clearAlert, 3000);
}
function clearAlert() {
document.querySelector('.alert').remove();
}
function validate_form() {
event.preventDefault();
// get form values
const user = document.getElementById('username').value;
const email = document.getElementById('email').value;
const pass = document.getElementById('key').value;
const name = document.getElementById('fullname').value;
// check form values are empty or not
if (user == "" || email == "" || pass == "" || name == "") {
showAlert('Fields Cannot be Empty!', 'alert alert-danger');
} else {
$.ajax({
type: 'POST',
url: 'register_script.php',
data: {
username: user,
email: email,
password: pass,
fullname: name
},
success: function(response) {
// parse the response message
let parsedResponse = JSON.parse(response);
let status = parsedResponse.status;
let message = parsedResponse.msg;
if (status == 'success') {
showAlert(message, 'alert alert-success');
// clear the form after succesful registration
clearForm();
sendEmail();
} else {
showAlert(message, 'alert alert-danger');
}
}
});
};
}
// send email with formData
function sendEmail() {
const form = document.getElementById('regis-form');
form.contact_number.value = Math.random() * 100000 | 0;
emailjs.sendForm('service_jqqodmg', 'template_khp9f0v', form)
.then(function() {
console.log('SUCCESS!');
}, function(error) {
console.log('FAILED...', error);
});
}
</script>
<?php include "includes/footer.php"; ?>