/
registration.php
95 lines (90 loc) · 2.59 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
<?php
require_once 'bootstrap.php';
use Assignment\UsernameValidator;
use Assignment\PasswordValidator;
use Assignment\EmailValidator;
use Assignment\URLValidator;
use Assignment\DateValidator;
use Assignment\Registration;
use Assignment\User;
$user = new User();
if($_POST){
$data = array(
'username' => new UsernameValidator($_POST['username'], true, 0, 20),
'password' => new PasswordValidator($_POST['password'], true, 0, 20),
'email' => new EmailValidator($_POST['email'], true),
'URL' => new URLValidator($_POST['url']),
'DOB' => new DateValidator($_POST['dob'], true, 18),
);
$reg = new Registration($data);
if(empty($reg->getErrors())){
$user->login($data);
$errors = array();
}else{
$errors = $reg->getErrors();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration Form</title>
<style>
fieldset {padding:3px}
input {display:block; margin: 0 auto 10px auto}
label {display:block; margin-bottom: 2px}
button {display: block; margin: 5px 0}
section {width:250px}
.errors{border-color:#e74c3c;color:#c0392b;}
.menu{border-color:#27ae60;color:#27ae60;}
</style>
</head>
<body>
<h1>Assignment Task 2 - Registration Form</h1>
<section>
<?php
if($user->isLoggedIn()){
?>
<fieldset class="menu">
<a href="secure.php">Secure</a>
<a href="logout.php">Logout</a>
</fieldset>
<?php
}else{
?>
<?php
if(isset($errors)){
?>
<fieldset class="errors">
<?php
foreach($errors as $key => $value){
echo $key . ': ' . $value . '<br/>';
}
?>
</fieldset>
<?php
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Enter your registration details</legend>
<label for="username">Username: </label>
<input type="text" maxlength="20" required name="username" id="username" value="<?php echo $_POST ? $_POST['username'] : ''; ?>">
<label for="username">Password: </label>
<input type="password" required name="password" id="password">
<label for="email">Email: </label>
<input type="email" required name="email" id="email" value="<?php echo $_POST ? $_POST['email'] : ''; ?>">
<label for="url">Webpage URL: </label>
<input type="url" name="url" id="url" value="<?php echo $_POST ? $_POST['url'] : ''; ?>">
<label for="dob">Date of birth: </label>
<input type="date" required name="dob" id="dob" value="<?php echo $_POST ? $_POST['dob'] : ''; ?>">
</fieldset>
<button type="submit" name="submit" formnovalidate>Submit Details</button>
</form>
</section>
<?php
}
?>
</body>
</html>