-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
168 lines (139 loc) · 4.17 KB
/
index.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
165
166
167
168
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Validation Form 1.0</title>
</head>
<body>
<?php
include 'valid.php';
if(isset($_POST['submit'])){
$wasSuccessful = true;
$text = sanitizeFormString($_POST['text']);
$email = sanitizeFormString($_POST['email']);
$phone = sanitizeFormString($_POST['phone']);
$domain = sanitizeFormString($_POST['domain']);
$postcode = sanitizeFormString($_POST['postcode']);
//TEXT ------------------------
$result = Validate::text($text, true);
switch($result){
case Validate::SHORT:
$text_error = 'Text is to short, Character length must be over 2';
$wasSuccessful = false;
break;
case Validate::LONG:
$text_error = 'Text is to long, Character length must be below 300';
$wasSuccessful = false;
break;
case Validate::TEXT_INVALID:
$text_error = 'Text can only container letters or white space.';
$wasSuccessful = false;
break;
case Validate::REQUIRED:
$text_error = 'This field is required';
$wasSuccessful = false;
break;
}
//END TEXT ----------------------
//EMAIL -----------------------------
$result = Validate::email($email, true);
switch($result){
case Validate::EMAIL_INVALID:
$email_error = 'Jack\'s email is invalid';
$wasSuccessful = false;
break;
case Validate::EMAIL_USER_INVALID:
$email_error = 'Username for email is invalid';
$wasSuccessful = false;
break;
case Validate::REQUIRED:
$email_error = 'Jack\'s email is required';
$wasSuccessful = false;
break;
}
//END Email ----------------------------
//DOMAIN -----------------------------
$result = Validate::domain($domain, true);
switch($result){
case Validate::DOM_INVALID:
$domain_error = 'Domain is invalid';
$wasSuccessful = false;
break;
case Validate::REQUIRED:
$domain_error = 'Domain is required';
$wasSuccessful = false;
break;
}
//END DOMAIN ----------------------------
//POSTCODE ------------------------
$result = Validate::postcode($postcode, true);
switch($result){
case Validate::POSTCODE_INVALID:
$postcode_error = 'Jack\'s post code is invalid';
$wasSuccessful = false;
break;
case Validate::REQUIRED:
$postcode_error = 'Jack\'s post code is required';
$wasSuccessful = false;
break;
}
//END POSTCODE ----------------------
//PHONE ------------------------
$result = Validate::phone($phone, true);
switch($result){
case Validate::SHORT:
$phone_error = 'Number is to short, Character length must be over 2';
$wasSuccessful = false;
break;
case Validate::LONG:
$phone_error = 'Number is to long, Character length must be below 12';
$wasSuccessful = false;
break;
case Validate::PHONE_INVALID:
$phone_error = 'Text can only contain numbers.';
$wasSuccessful = false;
break;
case Validate::REQUIRED:
$phone_error = 'This field is required';
$wasSuccessful = false;
break;
}
//END PHONE ----------------------
if($wasSuccessful == true) {
header("Location: index.php");
}
}
?>
<form class="" method="post" action="index.php" id='myform'>
<p>
<label for="text">Text</label>
<input id="text" name="text" type="text" >
<?php echo $text_error;?>
</p>
<p>
<label for="email">Email</label>
<input id="email" name="email" type="text" data-validation="email">
<?php echo $email_error;?>
</p>
<p>
<label for="phone">Phone</label>
<input id="phone" name="phone" type="phone" >
<?php echo $phone_error;?>
</p>
<p>
<label for="domain">Domain</label>
<input id="domain" name="domain" type="domain">
<?php echo $domain_error;?>
</p>
<p>
<label for="postcode">Postcode</label>
<input id="postcode" name="postcode" type="postcode">
<?php echo $postcode_error;?>
</p>
<button type="submit" name="submit">Submit</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script>
<script src="validationjs.js"></script>
</body>
</html>