Today I tried the uniform plugin.
Everything works as expected except one thing.
Each time I reload the page, the form content is being sent again. How can I prevent this?
controller:
<?php
use Uniform\Form;
return function ($kirby)
{
$form = new Form([
'name' => [
'rules' => ['required', 'min' => 3],
'message' => 'Please enter name',
],
'email' => [
'rules' => ['required', 'email'],
'message' => 'Please enter email address',
],
'select' => [
'rules' => ['required', 'in' => [['option1', 'option2', 'option3']]],
'message' => 'Please select an option',
],
'message' => [
'rules' => ['required', 'min' => 10],
'message' => 'Please enter a message',
],
]);
if ($kirby->request()->is('post')) {
$form->emailAction([
'to' => 'email@domain.tld',
'from' => 'email@domain.tld',
//'template' => 'html',
//'template' => 'email',
]);
}
return compact('form');
};
template snippet:
<style type="text/css">
label, input, textarea {
display: block;
}
.uniform__potty {
position: absolute;
left: -9999px;
}
.error {
border-bottom: 1px solid red;
}
</style>
<div class="fl cs12">
<div class="mwx1500 center bg-ffffff pas32">
<h1 class="tac">Contact Form</h1>
</div>
<div class="mwx1500 center bg-ffffff phs32">
<?php if ($form->success()): ?>
<h2>Thank you for your message. We will get back to you soon!</h2>
<?php else: ?>
<?php snippet('uniform/errors', ['form' => $form]) ?>
<?php endif; ?>
<form action="<?php echo $page->url() ?>" method="post">
<div class="form-group">
<label class="form-label" for="name">Name</label>
<input class="form-input<?php if ($form->error('name')): ?> error<?php endif; ?>" id="name" name="name" type="text" value="<?php echo $form->old('name') ?>" placeholder="Name">
</div>
<div class="form-group">
<label class="form-label" for="email">Email</label>
<input class="form-input<?php if ($form->error('email')): ?> error<?php endif; ?>" id="email" name="email" type="email" value="<?php echo $form->old('email') ?>" placeholder="Email">
</div>
<div class="form-group">
<label class="form-label" for="select">Select</label>
<?php $value = $form->old('select') ?>
<select class="form-select<?php if ($form->error('select')): ?> error<?php endif; ?>" id="select" name="select">
<option value="none">Select Option</option>
<option value="option1"<?php e($value=='option1', ' selected')?>>First</option>
<option value="option2"<?php e($value=='option2', ' selected')?>>Second</option>
<option value="option3"<?php e($value=='option3', ' selected')?>>Third</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="message">Message</label>
<textarea class="form-input<?php if ($form->error('message')): ?> error<?php endif; ?>" id="message" name="message" placeholder="Message" rows="3"><?php echo $form->old('message') ?></textarea>
</div>
<div class="form-group">
<?php echo csrf_field() ?>
<?php echo honeypot_field() ?>
</div>
<input type="submit" value="Submit">
</form>
</div>
</div>
Is this a session thing? i’m using plainkit-3.2.2 for testing.