-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-pet.php
66 lines (44 loc) · 1.43 KB
/
add-pet.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
<?php
/// This must come first when we need access to the current session
session_start();;
require("classes/components.php");
require("classes/utils.php");
/// if (!isset($_SESSION["user_role"]) || $_SESSION["user_role"] !== "Admin"){
/// header("Location: " . Utils::$projectFilePath . "/book-list.php");
/// }
$output = ""; ///< Variable to store output as a string.
/**
* Validates the form submission and creates a new pet if the form data is valid.
*/
if ($_SERVER["REQUEST_METHOD"] ==="POST" && isset($_POST["addSubmit"])) {
require("classes/pet.php");
$output = Pet::validate();
if(!$output){
$petId = Pet::create();
header("Location: " . Utils::$projectFilePath . "/pet.php?id=$petId");
}
}
Components::pageHeader("Add book", ["style"], ["mobile-nav"]);
?>
<main class="content-wrapper addPet-content">
<h2>Add new Book</h2>
<form
method="POST"
action="<?php echo $_SERVER["PHP_SELF"]; ?>"
enctype="multipart/form-data"
class="form"
>
<label>Name</label>
<input type="text" name="name">
<label>Species</label>
<input type="text" name="species">
<label>Price</label>
<input type="text" name="age">
<label>Cover image</label>
<input type="file" name="coverImage" value="">
<input class="button" type="submit" name="addSubmit" value="Add Book">
<?php if ($output) { echo $output; } ?>
</form>
<?php
Components::pageFooter();
?>