mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
- Created templates/partials/form/_licence.php (shared HTML, no auth logic)
- Created templates/partials/form/_format-website.php (shared HTML, no auth logic)
- Created src/FragmentRenderer.php helper for clean fragment rendering
- Created public/{admin,partage}/fragments/ subdirectories
- Created thin fragment endpoint files: auth guard + data fetch + render template
- Updated all hx-post references in templates to new fragments/ paths
- Updated partage/index.php routing for new fragments subdirectory
- Kept old fragment files as thin delegates for backward compat
- Updated nginx config: added PHP handler in /partage/ location block
60 lines
2.8 KiB
PHP
60 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* File input partial.
|
|
*
|
|
* Variables consumed:
|
|
* string $name — input name attribute (used for id too unless $id set)
|
|
* string $label — visible label text
|
|
* string $accept — MIME types / extensions for the accept attribute (e.g. 'image/jpeg,image/png')
|
|
* string|null $hint — optional hint shown in <small> below the input
|
|
* bool $required — whether the field is required; default false
|
|
* bool $multiple — whether to allow multiple file selection; default false
|
|
* string|null $id — override the id attribute (defaults to $name)
|
|
* string|null $fieldName — validation field name for HTMX inline validation ('couverture', 'note_intention', 'tfe', 'annexes')
|
|
*/
|
|
|
|
$accept = $accept ?? '';
|
|
$hint = $hint ?? null;
|
|
$hintRaw = $hintRaw ?? false; // when true, $hint is emitted as raw HTML
|
|
$required = $required ?? false;
|
|
$multiple = $multiple ?? false;
|
|
$id = $id ?? $name;
|
|
$fieldName = $fieldName ?? $name; // validation field name
|
|
$previewId = 'fp-' . htmlspecialchars($id);
|
|
|
|
// Determine HTMX POST endpoint for inline file validation
|
|
if (defined('ADMIN_MODE') && ADMIN_MODE) {
|
|
$validateUrl = '/admin/fragments/validate-file.php';
|
|
} else {
|
|
$validateUrl = '/partage/fragments/validate-file.php';
|
|
}
|
|
?>
|
|
<div>
|
|
<label for="<?= htmlspecialchars($id) ?>"><?= htmlspecialchars($label) ?><?= $required ? ' <span class="asterisk">*</span>' : '' ?></label>
|
|
<!-- HTMX validation: scoped to this field -->
|
|
<form class="admin-file-input file-validation-form"
|
|
hx-post="<?= htmlspecialchars($validateUrl) ?>"
|
|
hx-encoding="multipart/form-data"
|
|
hx-trigger="change from:input[type='file']"
|
|
hx-target="find .file-validation-msg"
|
|
hx-swap="innerHTML"
|
|
hx-sync="replace">
|
|
<input type="hidden" name="field_name" value="<?= htmlspecialchars($fieldName) ?>">
|
|
<input type="hidden" name="admin_mode" value="<?= ($adminMode ?? false) ? '1' : '0' ?>">
|
|
<input type="file"
|
|
id="<?= htmlspecialchars($id) ?>"
|
|
name="<?= htmlspecialchars($name) ?><?= $multiple ? '[]' : '' ?>"
|
|
<?= $accept ? 'accept="' . htmlspecialchars($accept) . '"' : '' ?>
|
|
<?= $multiple ? 'multiple' : '' ?>
|
|
<?= $required ? 'required' : '' ?>
|
|
data-preview="<?= $previewId ?>">
|
|
<div class="file-validation-msg" aria-live="polite"></div>
|
|
<div id="<?= $previewId ?>" class="file-preview-list" aria-live="polite"></div>
|
|
<?php if ($hint): ?>
|
|
<small><?= $hintRaw ? $hint : htmlspecialchars($hint) ?></small>
|
|
<?php endif; ?>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
unset($accept, $hint, $hintRaw, $required, $multiple, $id, $fieldName, $previewId, $validateUrl);
|