-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_form.php
87 lines (76 loc) · 2.91 KB
/
product_form.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
<?php
$title = 'Sell product';
require __DIR__ . '/utils/protec_acess.php';
require __DIR__ . '/db/UsersDB.php';
require __DIR__ . '/db/ProductsDB.php';
require __DIR__ . '/db/OrdersDB.php';
include __DIR__ . '/incl/head.php';
include __DIR__ . '/incl/nav.php';
?>
<?php
// init
$errors = [];
$usersDB = new UsersDB();
$productsDB = new ProductsDB();
// $productsDB->create(['name' => 'Nikes', 'price' => 49.99, 'product_info' => 'Dummy text', 'img_link' => 'vse.cz', 'category_id' => 4, $user_id]);
if (!empty($_POST)) {
$name = $_POST['name'];
$price = $_POST['price'];
$product_info = $_POST['product_info'];
$img_link = $_POST['img_link'];
$category_id = $_POST['category_id'];
// VALIDATE INPUT
require __DIR__ . '/utils/validate_product.php';
// CREATE IF NP
if (!count($errors)) {
$productsDB->create(['name' => $name, 'price' => $price, 'product_info' => $product_info, 'img_link' => $img_link, 'category_id' => $category_id, 'user_id' => $user_id]);
header("Location: profile.php?ref=success");
exit();
} else {
array_push($errors, 'Please try again ...');
}
}
?>
<body class="d-flex flex-column min-vh-100">
<div class="header">
<h2>Add product to sell</h2>
<?php if (!empty($errors)) : ?>
<div class="alert alert-danger" role="alert">
<?php foreach ($errors as $error) : ?>
<div><?php echo $error; ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<form method="post" action="product_form.php">
</div>
<div class="mb-3">
<label>Name of the product</label>
<input class="form-control" name="name" value="<?php echo isset($name) ? $name : '' ?>">
</div>
<div class="mb-3">
<label>Price</label>
<input class="form-control" name="price" type="price" value="<?php echo isset($price) ? $price : '' ?>">
</div>
<div class="mb-3">
<label>Product description</label>
<input class="form-control" name="product_info" type="product_info "
value="<?php echo isset($product_info) ? $product_info : '' ?>">
</div>
<div class="mb-3">
<label>Product image link</label>
<input class="form-control" name="img_link" type="img_link "
value="<?php echo isset($img_link) ? $img_link : '' ?>">
</div>
<select class="form-select mb-4" aria-label="Default select example" name="category_id">
<option value="1">Shoes</option>
<option value="2">T-shirts</option>
<option value="3">Hoodies</option>
<option value="4">Other</option>
</select>
<div class="mb-3">
<button type="submit" class="btn btn-secondary" name="submit">Submit</button>
</div>
</form>
</body>
<?php include __DIR__ . '/incl/footer.php' ?>