Files
plugi/extensions/plugi-ext-form/blocks/form-wrapper/view.php
T
deepDiverPaul 80e60d6823 translate form extension UI to English
Replace German labels, prompts, validation messages, and submission text across the form admin and block views with English.
Remove redundant LICENSE files from the form and sitemap extensions.
2026-11-24 10:56:44 +01:00

128 lines
6.1 KiB
PHP

<?php
$formRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
$id = $block->setting("formId");
if ($id > 0):
$form = $formRepository->findWithId($id);
$fields = json_decode($form["fields"], true);
?>
<div class="max-w-2xl mx-auto">
<div x-data="{data: {fields : {}}, status: 'idle', submitted: false}">
<form x-show="!submitted" x-transition:leave x-transition:leave-opacity-0 x-on:submit.prevent="
status = 'busy';
fetch('/ext--form/submit?id=<?= $id ?>', {
method: 'POST',
body: JSON.stringify(data)
}).finally(() => {
status = 'idle';
submitted = true;
})
">
<?php foreach ($fields as $field):
$fieldName = $field["name"];
$fieldLabel = $field["label"];
$fieldType = $field["type"];
$fieldRequired =
isset($field["required"]) && $field["required"];
$fieldOptions = isset($field["options"])
? $field["options"]
: [];
?>
<div class="form-control mb-4">
<label class="label mb-1">
<span class="label-text font-medium">
<?= $fieldLabel ?>
<?php if ($fieldRequired): ?>
<span class="text-error ml-1">*</span>
<?php endif; ?>
</span>
</label>
<?php if ($fieldType === "select"): ?>
<select x-model="data.fields.<?= $fieldName ?>" class="select select-bordered w-full" <?= $fieldRequired
? "required"
: "" ?>>
<option value="" disabled selected>Please select</option>
<?php foreach ($fieldOptions as $option): ?>
<option value="<?= $option[
"value"
] ?>"><?= $option["label"] ?></option>
<?php endforeach; ?>
</select>
<?php elseif ($fieldType === "checkbox"): ?>
<div class="space-y-2">
<?php foreach ($fieldOptions as $option): ?>
<label class="label cursor-pointer gap-3">
<span class="label-text"><?= $option[
"label"
] ?></span>
<input type="checkbox" value="<?= $option[
"value"
] ?>" x-model="data.fields.<?= $fieldName ?>" class="checkbox checkbox-sm checkbox-primary" />
</label>
<?php endforeach; ?>
</div>
<?php elseif ($fieldType === "radio"): ?>
<div class="space-y-2">
<?php foreach ($fieldOptions as $option): ?>
<label class="label cursor-pointer gap-3">
<span class="label-text"><?= $option[
"label"
] ?></span>
<input type="radio" name="<?= $fieldName ?>" value="<?= $option[
"value"
] ?>" x-model="data.fields.<?= $fieldName ?>" class="radio radio-sm radio-primary" />
</label>
<?php endforeach; ?>
</div>
<?php elseif ($fieldType === "textarea"): ?>
<textarea x-model="data.fields.<?= $fieldName ?>" class="textarea textarea-bordered w-full" placeholder="<?= $fieldLabel ?>" <?= $fieldRequired
? "required"
: "" ?> rows="4"></textarea>
<?php else: ?>
<input type="<?= $fieldType ?>" x-model="data.fields.<?= $fieldName ?>" class="input input-bordered w-full" placeholder="<?= $fieldLabel ?>" <?= $fieldRequired
? "required"
: "" ?>>
<?php endif; ?>
</div>
<?php
endforeach; ?>
<div class="mt-6">
<button type="submit" class="btn btn-primary w-full" :disabled="status === 'busy'">
<span x-show="status === 'idle'">
<i class="ph-duotone ph-paper-plane-tilt"></i>
Submit
</span>
<span x-show="status === 'busy'">
<span class="loading loading-spinner loading-sm"></span>
Sending...
</span>
</button>
</div>
</form>
<div x-show="submitted" x-transition:enter x-transition:enter-opacity-0 x-transition:enter-delay-100 class="card bg-base-100 shadow-lg mt-4">
<div class="card-body items-center text-center">
<div class="w-16 h-16 rounded-full bg-success/20 flex items-center justify-center mb-2">
<i class="ph-duotone ph-check text-3xl text-success"></i>
</div>
<h3 class="card-title text-lg">Thank you!</h3>
<p class="text-base-content/60">Your message has been sent successfully.</p>
</div>
</div>
</div>
</div>
<?php
else:
?>
<div class="form-wrapper max-w-2xl mx-auto">
<div class="card bg-base-200 border-2 border-dashed border-base-300">
<div class="card-body items-center text-center py-8">
<i class="ph-duotone ph-plus-circle text-4xl text-base-content/30"></i>
<p class="text-sm text-base-content/50 mt-2">Select a form in the settings</p>
</div>
</div>
</div>
<?php
endif; ?>