-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathindex.php
More file actions
106 lines (97 loc) · 4.57 KB
/
index.php
File metadata and controls
106 lines (97 loc) · 4.57 KB
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
<?php
//I made some little changes in the code. I would make php and html in separate files and add js for the loops as well. But probable not for this simple example
//I do not think we need a class for the example. But we can use it like this if you want
/* class Interview {
protected $title = 'Interview test';
protected $people = array(
array('id' => 1, 'first_name' => 'John', 'last_name' => 'Smith', 'email' => 'john.smith@hotmail.com'),
array('id' => 2, 'first_name' => 'Paul', 'last_name' => 'Allen', 'email' => 'paul.allen@microsoft.com'),
array('id' => 3, 'first_name' => 'James', 'last_name' => 'Johnston', 'email' => 'james.johnston@gmail.com'),
array('id' => 4, 'first_name' => 'Steve', 'last_name' => 'Buscemi', 'email' => 'steve.buscemi@yahoo.com'),
array('id' => 5, 'first_name' => 'Doug', 'last_name' => 'Simons', 'email' => 'doug.simons@hotmail.com')
);
protected $lipsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus incidunt, quasi aliquid, quod officia commodi magni eum? Provident, sed necessitatibus perferendis nisi illum quos, incidunt sit tempora quasi, pariatur natus.';
//I can create setter here and the class can be more flexile and reusable for the similar pages.
public function __get($property) {
if (isset($property)) {
return $this->$property;
}
}
public function getPersonToSubmit($post) {
if ($post) {
if (!empty(implode($post))) {
return implode(' ', $post);
}
return 'Imput the data!';
}
return 'Did not get $_POST.';
}
}
$obj = new Interview();
$title = $obj->title;
$lipsum = $obj->lipsum;
$people = $obj->people;
$personToSubmit = $obj->getPersonToSubmit($_POST) */
//we could replace all this things with the code I comented above.
$title = 'Interview test';
$people = array(
array('id' => 1, 'first_name' => 'John', 'last_name' => 'Smith', 'email' => 'john.smith@hotmail.com'),
array('id' => 2, 'first_name' => 'Paul', 'last_name' => 'Allen', 'email' => 'paul.allen@microsoft.com'),
array('id' => 3, 'first_name' => 'James', 'last_name' => 'Johnston', 'email' => 'james.johnston@gmail.com'),
array('id' => 4, 'first_name' => 'Steve', 'last_name' => 'Buscemi', 'email' => 'steve.buscemi@yahoo.com'),
array('id' => 5, 'first_name' => 'Doug', 'last_name' => 'Simons', 'email' => 'doug.simons@hotmail.com')
);
$lipsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus incidunt, quasi aliquid, quod officia commodi magni eum? Provident, sed necessitatibus perferendis nisi illum quos, incidunt sit tempora quasi, pariatur natus.';
//I moved the if statement from html to here. I am not sure it's good solution. but for me it looks better
$personToSubmit = 'Imput the data!';
if ($_POST) {
if (!empty(implode($_POST))) {//I could check all the keys of the array.
$personToSubmit = implode(' ', $_POST);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Interview test</title>
<style>
body {font: normal 14px/1.5 sans-serif;}
</style>
</head>
<body>
<h1><?php echo $title; ?></h1>
<?php
for ($i = 0; $i < 10; $i++) {
echo '<p>' . $lipsum . '</p>';
}
?>
<hr>
<form method="post" action=""><!--I removed $_SERVER['REQUEST_URI'].we do not need it here and it's not safe-->
<p><label for="firstName">First name</label> <input type="text" name="first_name" id="firstName"></p>
<p><label for="lastName">Last name</label> <input type="text" name="last_name" id="lastName"></p>
<p><label for="email">Email</label> <input type="text" name="email" id="email"></p>
<p><input type="submit" value="Submit" /></p>
</form>
<p><strong>Person</strong> <?php echo $personToSubmit; ?></p>
<hr>
<table>
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php foreach ($people as $person) { ?>
<tr>
<td><?php echo $person['first_name']; ?></td>
<td><?php echo $person['last_name']; ?></td>
<td><?php echo $person['email']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>