php class User public name public surname public age public email publ

 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
<?php
class User{
public $name;
public $surname;
public $age;
public $email;
public function setData($name, $surname, $age, $email){
$this->name = $name;
$this->surname = $surname;
$this->age = $age;
$this->email = $email;
}
public function showData(){
echo "Name: ".$this->name."<br>";
echo "Surname: ".$this->surname."<br>";
echo "Age: ".$this->age."<br>";
echo "Email: ".$this->email."<br>";
}
}
?>
<style type="text/css">
.wrapper{
width: 200px;
margin: 0 auto;
text-align:center;
}
input{
margin-bottom: 10px;
width: 100%;
}
.btn{
width: 100%;
}
</style>
<div class="wrapper">
<a href="Task2.php">prev</a>
| Task 3 |
<a href="Task4.php">next</a>
<hr>
<form method="post">
<input type="text" name="name" placeholder="Name..."/><br>
<input type="text" name="surname" placeholder="Surname..."/><br>
<input type="text" name="age" placeholder="Age..."/><br>
<input type="text" name="email" placeholder="Email..."/><br>
<input type="submit" class="btn" name="submit" value="Send"/>
</form>
<?php
if(isset($_POST["submit"]))
{
if (empty($_POST["name"]) || empty($_POST["surname"]) || empty($_POST["age"]) || empty($_POST["email"])) {
echo "Some fields is empty!";
}
else {
$obj = new User();
$obj->setData($_POST["name"], $_POST["surname"], $_POST["age"], $_POST["email"]);
$obj->showData();
}
}
?>
</div>