2026-06-11 19:03:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
2026-06-14 07:16:13 +02:00
|
|
|
use Reservair\Templating\RsvTemplateEngine;
|
2026-06-11 19:03:29 +02:00
|
|
|
|
|
|
|
|
class RsvFormHtmlRenderer {
|
|
|
|
|
public function draw(RsvFormDefinition $form): bool {
|
|
|
|
|
if (!$form->hasElements()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form_id = esc_attr($form->getId());
|
|
|
|
|
?>
|
|
|
|
|
<div>
|
|
|
|
|
<form class="reservair-form confirmation"
|
|
|
|
|
id="<?= $form_id ?>"
|
|
|
|
|
onsubmit="RsvFormSender.send_form(event)"
|
|
|
|
|
method="POST">
|
|
|
|
|
|
|
|
|
|
<?php foreach ($form->getElements() as $element): ?>
|
|
|
|
|
<?php $this->draw_element($element); ?>
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
|
|
|
|
</form>
|
2026-06-14 07:16:13 +02:00
|
|
|
<?php $this->draw_success_template($form); ?>
|
2026-06-11 19:03:29 +02:00
|
|
|
</div>
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 07:16:13 +02:00
|
|
|
/**
|
|
|
|
|
* Emits the admin-configured success message as an inert <template> that the
|
|
|
|
|
* client clones once the form is submitted. A <reservation-summary> element
|
|
|
|
|
* expands to a placeholder div that RsvFormSender fills with the visitor's
|
|
|
|
|
* selected slots.
|
|
|
|
|
*/
|
|
|
|
|
private function draw_success_template(RsvFormDefinition $form): void {
|
|
|
|
|
$message = trim($form->getSuccessMessage());
|
|
|
|
|
if ($message === '') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global $rsv_template_registry;
|
|
|
|
|
$engine = new RsvTemplateEngine(registry: $rsv_template_registry);
|
|
|
|
|
|
|
|
|
|
// Sanitize admin HTML before rendering, allowing the registered template
|
|
|
|
|
// custom elements through so the engine can expand them.
|
|
|
|
|
$allowed = $rsv_template_registry->kses_allowed(wp_kses_allowed_html('post'));
|
|
|
|
|
$html = $engine->render(wp_kses($message, $allowed));
|
|
|
|
|
?>
|
|
|
|
|
<template class="rsv-form-success"><?= $html ?></template>
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-11 19:03:29 +02:00
|
|
|
public function draw_element(RsvFormElementDefinition $data): void {
|
|
|
|
|
global $rsv_form_registry;
|
|
|
|
|
|
|
|
|
|
$handler = $rsv_form_registry->get($data->getType());
|
|
|
|
|
if ($handler === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$handler->draw($data);
|
|
|
|
|
}
|
|
|
|
|
}
|