36037-vm/views/partials/product_form.php
Flatlogic Bot b6296eed55 Version 1
2025-11-22 17:18:03 +00:00

29 lines
1.6 KiB
PHP

<?php
$product = $product ?? null; // Use existing product data or null for a new one
$is_edit = isset($product) && $product['id'];
?>
<form action="api/<?= $is_edit ? 'update_product.php' : 'create_product.php' ?>" method="post">
<?php if ($is_edit): ?>
<input type="hidden" name="id" value="<?= htmlspecialchars($product['id']) ?>">
<?php endif; ?>
<div class="mb-3">
<label for="name" class="form-label">Product Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?= htmlspecialchars($product['name'] ?? '') ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3"><?= htmlspecialchars($product['description'] ?? '') ?></textarea>
</div>
<div class="mb-3">
<label for="price" class="form-label">Price</label>
<input type="number" class="form-control" id="price" name="price" step="0.01" value="<?= htmlspecialchars($product['price'] ?? '') ?>" required>
</div>
<div class="mb-3">
<label for="barcode" class="form-label">Barcode</label>
<input type="text" class="form-control" id="barcode" name="barcode" value="<?= htmlspecialchars($product['barcode'] ?? '') ?>">
</div>
<button type="submit" class="btn btn-primary"><?= $is_edit ? 'Update' : 'Create' ?> Product</button>
<?php if ($is_edit): ?>
<a href="dashboard.php?page=admin_products" class="btn btn-secondary">Cancel</a>
<?php endif; ?>
</form>