-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
142 lines (141 loc) · 5.24 KB
/
signup.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
<?php include 'db_connect.php' ?>
<?php
if(isset($_GET['id'])){
$qry = $conn->query("SELECT * FROM users where id = {$_GET['id']}");
foreach($qry->fetch_array() as $k => $v){
$$k = $v;
}
}
?>
<div class="container py-3">
<div class="col-lg-12">
<div class="card bg-light">
<div class="card-body">
<h3><b><?php echo isset($id) ? "Manage":'Create' ?> Account</b></h3>
<hr>
<form action="" id="manage_account">
<input type="hidden" name="id" value="<?php echo isset($id) ? $id : '' ?>">
<div class="col-md-12">
<div class="row">
<div class="col-md-6 border-right">
<div class="form-group">
<label class="control-label">First Name</label>
<input type="text" class="form-control form-control-sm" name="firstname" required value="<?php echo isset($firstname) ? $firstname : '' ?>">
</div>
<div class="form-group">
<label class="control-label">Middle Name</label>
<input type="text" class="form-control form-control-sm" name="middlename" value="<?php echo isset($middlename) ? $middlename : '' ?>">
</div>
<div class="form-group">
<label class="control-label">Last Name</label>
<input type="text" class="form-control form-control-sm" name="lastname" required value="<?php echo isset($lastname) ? $lastname : '' ?>">
</div>
<div class="form-group">
<label class="control-label">Contact #</label>
<input type="text" class="form-control form-control-sm" name="contact" required value="<?php echo isset($contact) ? $contact : '' ?>">
</div>
<div class="form-group">
<label class="control-label">Address</label>
<textarea name="address" id="" cols="30" rows="4" class="form-control" required><?php echo isset($address) ? $address : '' ?></textarea>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="" class="control-label">Avatar</label>
<input type="file" class="form-control form-control-sm" name="img" onchange="displayImg(this,$(this))">
</div>
<div class="form-group d-flex justify-content-center">
<img src="<?php echo isset($avatar) ? 'assets/uploads/'.$avatar :'' ?>" alt="" id="cimg" class="img-fluid img-thumbnail">
</div>
<div class="form-group">
<label class="control-label">Email</label>
<input type="email" class="form-control form-control-sm" name="email" required value="<?php echo isset($email) ? $email : '' ?>">
<small id="#msg"></small>
</div>
<div class="form-group">
<label class="control-label">Password</label>
<input type="password" class="form-control form-control-sm" name="password" <?php echo isset($id) ? "":'required' ?>>
<small><i><?php echo isset($id) ? "Leave this blank if you dont want to change you password":'' ?></i></small>
</div>
<div class="form-group">
<label class="label control-label">Confirm Password</label>
<input type="password" class="form-control form-control-sm" name="cpass" <?php echo isset($id) ? 'required' : '' ?>>
<small id="pass_match" data-status=''></small>
</div>
</div>
</div>
<hr>
<div class="col-lg-12 text-right justify-content-center d-flex">
<button class="btn btn-primary mr-2"><?php echo isset($id) ? "Update":'Create' ?> Account</button>
<button class="btn btn-secondary" type="reset">Clear</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<style>
img#cimg{
max-height: 15vh;
/*max-width: 6vw;*/
}
</style>
<script>
$('[name="password"],[name="cpass"]').keyup(function(){
var pass = $('[name="password"]').val()
var cpass = $('[name="cpass"]').val()
if(cpass == '' ||pass == ''){
$('#pass_match').attr('data-status','')
}else{
if(cpass == pass){
$('#pass_match').attr('data-status','1').html('<i class="text-success">Password Matched.</i>')
}else{
$('#pass_match').attr('data-status','2').html('<i class="text-danger">Password does not match.</i>')
}
}
})
function displayImg(input,_this) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#cimg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$('#manage_account').submit(function(e){
e.preventDefault()
$('input').removeClass("border-danger")
start_load()
$('#msg').html('')
if($('#pass_match').attr('data-status') != 1){
if($("[name='password']").val() !=''){
$('[name="password"],[name="cpass"]').addClass("border-danger")
end_load()
return false;
}
}
$.ajax({
url:'ajax.php?action=save_user',
data: new FormData($(this)[0]),
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success:function(resp){
if(resp == 1){
alert_toast('Data successfully saved.',"success");
setTimeout(function(){
location.replace('index.php')
},750)
}else if(resp == 2){
$('#msg').html("<div class='alert alert-danger'>Email already exist.</div>");
$('[name="email"]').addClass("border-danger")
end_load()
}
}
})
})
</script>