Files
habit-tracker/app/Views/habits/form.php
T

59 lines
2.3 KiB
PHP

<?php $isEdit = !empty($habit['id']); ?>
<section class="form-panel">
<h1><?= $isEdit ? 'Habit bearbeiten' : 'Habit erstellen' ?></h1>
<form method="post" action="index.php?route=<?= $isEdit ? 'habits/update' : 'habits/store' ?>" class="form">
<?= csrf_field() ?>
<?php if ($isEdit): ?>
<input type="hidden" name="id" value="<?= (int) $habit['id'] ?>">
<?php endif; ?>
<label for="title">Name des Habits</label>
<input
id="title"
name="title"
type="text"
class="<?= !empty($errors['title']) ? 'input-error' : '' ?>"
value="<?= e($habit['title'] ?? '') ?>"
required
aria-describedby="title-error"
>
<?php if (!empty($errors['title'])): ?>
<small id="title-error" class="field-error"><?= e($errors['title']) ?></small>
<?php endif; ?>
<label for="description">Beschreibung <span>optional</span></label>
<textarea id="description" name="description" rows="4"><?= e($habit['description'] ?? '') ?></textarea>
<label for="category_id">Kategorie</label>
<select id="category_id" name="category_id">
<option value="">Keine Kategorie</option>
<?php foreach ($categories as $category): ?>
<option value="<?= (int) $category['id'] ?>" <?= (string) ($habit['category_id'] ?? '') === (string) $category['id'] ? 'selected' : '' ?>>
<?= e($category['name']) ?>
</option>
<?php endforeach; ?>
</select>
<label for="target_per_week">Ziel pro Woche</label>
<input
id="target_per_week"
name="target_per_week"
type="number"
class="<?= !empty($errors['target_per_week']) ? 'input-error' : '' ?>"
min="1"
max="7"
value="<?= e((string) ($habit['target_per_week'] ?? '3')) ?>"
required
aria-describedby="target-error"
>
<?php if (!empty($errors['target_per_week'])): ?>
<small id="target-error" class="field-error"><?= e($errors['target_per_week']) ?></small>
<?php endif; ?>
<button type="submit"><?= $isEdit ? 'Speichern' : 'Erstellen' ?></button>
</form>
</section>