Kirby Uniform
A versatile Kirby 2 plugin to handle web form actions.
This is Uniform v3.0-beta. For Uniform v2.3 head over to the v2 branch.
Builtin actions:
- Email: Send the form data by email.
- EmailSelect: Choose from multiple recipients to send the form data by email.
- Log: Log the form data to a file.
- Login: Log in to the Kirby frontend.
- Webhook: Send the form data as an HTTP request to a webhook.
Quick example
Controller:
<?php
use Uniform\Form;
return function ($site, $pages, $page) {
$form = new Form([
'email' => [
'rules' => ['required', 'email'],
'message' => 'Email is required',
],
'message' => [],
]);
if (r::is('POST')) {
$form->emailAction([
'to' => 'me@example.com',
'from' => 'info@example.com',
]);
}
return compact('form');
};
Template:
<form action="<?php echo $page->url() ?>" method="POST">
<input name="email" type="email" value="<?php echo $form->old('email'); ?>">
<textarea name="message"><?php echo $form->old('message'); ?></textarea>
<?php echo csrf_field(); ?>
<?php echo honeypot_field(); ?>
<input type="submit" value="Submit">
</form>
<?php if ($form->success()): ?>
Success!
<?php else: ?>
<?php snippet('uniform/errors', ['form' => $form]); ?>
<?php endif; ?>
Installation
Kirby CLI
Get the Kirby CLI and run kirby plugin:install mzur/kirby-uniform
.
Traditional
Download the repository and extract it to site/plugins/uniform
.
Composer
Initialize the composer.json
with:
{
"minimum-stability": "dev",
"repositories": [
{
"type": "git",
"url": "https://github.com/jevets/kirby-form.git"
},
{
"type": "git",
"url": "https://github.com/jevets/kirby-flash.git"
}
]
}
Run composer require mzur/kirby-uniform
. Then add the second require
to the index.php
like this:
// load kirby
require(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');
require 'vendor'.DS.'autoload.php';
Be sure to include the new vendor
directory in your deployment.
Setup
Add this to your CSS:
.uniform__potty {
position: absolute;
left: -9999px;
}
If you have a single language site you can choose the language Uniform should use in site/config/config.php
(default is en
):
c::set('uniform.language', 'de');
See here for all supported languages.
Note: Disable the Kirby cache for pages where you use Uniform to make sure the form is generated dynamically.
Documentation
For the full documentation head over to Read the Docs.
Questions
See the answers in the docs, post an issue if you think it is a bug or create a topic in the forum if you need help (be sure to use the uniform
tag or mention @mzur
).
Contributing
Contributions are always welcome!