From 85f6ec1bc8f094e769835e9836b9fab7fb9e6ace Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Thu, 23 May 2024 11:18:21 +0200
Subject: [PATCH] output dei valori giĆ  esistenti per modificarli nella pagina edit (parte 134)

---
 views/Products/edit.php |    4 ++++
 views/Products/form.php |   11 +++++++++++
 views/Products/new.php  |   12 +-----------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/views/Products/edit.php b/views/Products/edit.php
index 29fb647..6b9e0fe 100644
--- a/views/Products/edit.php
+++ b/views/Products/edit.php
@@ -1,6 +1,10 @@
 <body>
     <h1>Edit Product</h1>
 
+    <form method="post" action="/products/<?= $product["id"]?>/update">
+        <?php require "form.php"?>
+    </form>
+
     <p><a href="/products/<?= $product["id"] ?>/show" >Cancel</a></p>
 </body>
 </html>
\ No newline at end of file
diff --git a/views/Products/form.php b/views/Products/form.php
new file mode 100644
index 0000000..2b9dcd9
--- /dev/null
+++ b/views/Products/form.php
@@ -0,0 +1,11 @@
+<label for="name">Name</label>
+<input type="text", id="name", name="name" value="<?= $product["name"] ?? ""?>">
+
+<?php if (isset($errors["name"])): ?>
+            <p><?= $errors["name"] ?></p>
+<?php endif; ?>
+
+<label for="description">Description</label>
+<textarea id="description", name="description"><?= $product["description"] ?? ""?></textarea>
+
+<button>Save</button>
\ No newline at end of file
diff --git a/views/Products/new.php b/views/Products/new.php
index 4de2e4a..29fe04d 100644
--- a/views/Products/new.php
+++ b/views/Products/new.php
@@ -1,17 +1,7 @@
 <body>
     <h1>New product</h1>
     <form method="post" action="/products/create">
-        <label for="name">Name</label>
-        <input type="text", id="name", name="name">
-
-        <?php if (isset($errors["name"])): ?>
-            <p><?= $errors["name"] ?></p>
-        <?php endif; ?>
-
-        <label for="description">Description</label>
-        <textarea id="description", name="description"></textarea>
-
-        <button>Save</button>
+        <?php require "form.php"?>
     </form>
 </body>
 </hmtl>
\ No newline at end of file

--
Gitblit v1.8.0