-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
144 lines (129 loc) · 5.52 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
143
144
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Pulse Electronics</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/newCustomer.css">
<link rel="icon" type="images/png" href="images/logo.png">
</head>
<body>
<div class="card container" style="margin-top: 30px; width: 70%; margin-bottom: 35px;">
<h2 style="text-align: center; margin: 30px;">Sign Up form</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div>
<label for="fname">First Name<span style="color: red">*</span></label> :
<input type="text" class="form-control" name="fname" placeholder="First name">
<div class="invalid-feedback"><?php echo $fnameErr; ?></div>
<div class="valid-feedback"></div>
</div>
<div>
<label for="lname">Last Name<span style="color: red">*</span></label> :
<input type="text" class="form-control" name="lname" placeholder="Last name">
<div class="invalid-feedback"><?php echo $lnameErr; ?></div>
<div class="valid-feedback"></div>
</div>
<div>
<label for="mailid">Email ID<span style="color: red">*</span></label> :
<input type="email" class="form-control" name="mailid" placeholder="Email ID">
<div class="invalid-feedback"><?php echo $mailidErr; ?></div>
<div class="valid-feedback"></div>
</div>
<div>
<label for="website">Website<span style="color: red">*</span></label> :
<input type="text" class="form-control" name="website"
placeholder="Enter your website address">
<div class="invalid-feedback">The website cannot be empty.</div>
<div class="valid-feedback"></div>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember"> I agree to the <a href="tnc.html"> terms and
conditions.</a>
<div class="valid-feedback"></div>
<div class="invalid-feedback">Check this checkbox to continue.</div>
</label>
<div style="text-align: center;"><button type="submit" class="btn btn-outline-primary">Submit</button></div>
</form>
</div>
</body>
<script>
// Disable form submissions if there are invalid fields
(function () {
'use strict';
window.addEventListener('load', function () {
// Get the forms we want to add validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
<?php
// define variables and set to empty values
$fname = $lname = $mailid = $addressl1 = $addressl2 = $addressl3 = $state = "";
$fnameErr = $lnameErr = $mailidErr = $addressl1Err = $addressl2Err = $addressl3Err = $stateErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if(empty($_POST["fname"])){
$fnameErr = "First Name is required";
}
else{
$fname = test_input($_POST["fname"]);
if(!preg_match("/^[a-zA-Z ]*$/",$fname)){
$fnameErr = "The first name does not contain number and special characters!!";
}
}
if(empty($_POST["lname"])){
$lnameErr = "First Name is required";
}
else{
$fname = test_input($_POST["lname"]);
if(!preg_match("/^[a-zA-Z ]*$/",$lname)){
$lnameErr = "The last name does not contain number and special characters!!";
}
}
if(empty($_POST["mailid"])){
$mailidErr = "Email ID is required";
}
else{
$mailid = test_input($_POST["mailid"]);
if(filter_var($_POST["mailid"],FILTER_VALIDATE_EMAIL)){
}
else{
$mailidErr = "The email ID is not valid.";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
</html>
<!-- Theory
1. What is PHP
2. What is use of PHP
3. Limitation(4) and advantages(4) of PHP
4. Difference between PHP and JS(5 - 6)
5. PHP variable declaration (syntax)
6. PHP functions (syntax)
7. GET method (syntax)
8. POST method (syntax) and difference
9. Error message (syntax)
10. PHP form validations (form, action, attribute for method i.e. post and get, validate URL and Email) write all the function syntax
-->