Skip to main content

Snippets

The Kirby Email Manager plugin provides flexible options for integrating email forms into your Kirby CMS project. Depending on your requirements, you can choose one of the following approaches.

Simple and Complete Solution

For the easiest integration, use the form-wrapper.php snippet. It handles everything for you, including:

  • Session handling for success messages.
  • Displaying the form.
  • Showing a success message after form submission.
<?php snippet('email-manager/form-wrapper'); ?>

This is the quickest way to set up a fully functioning email form.

Custom Solution

For more control, you can separate the form display and the success message:

  • Use form.php to display the form.
  • Use success-message.php to display a standalone success message.
<?php
snippet('email-manager/form');
snippet('email-manager/success-message');
?>

You can choose whether or not to include session handling.

Block Integration

When using the Email Manager as a block, the plugin provides a default block snippet at blocks/email-manager.php, which automatically uses form-wrapper.php.

To create a custom block, you can override the block snippet and use the provided snippets (form.php and success-message.php) with or without session handling.

<?php snippet('email-manager/form', ['block' => $block]); ?>
<?php snippet('email-manager/success-message'); ?>

If you just want to add extra content around the form, you can use the wrapper in your custom block as well.

<?php snippet('email-manager/form-wrapper', ['block' => $block]); ?>

Session Handling

The Email Manager plugin uses session handling to display success messages after form submission. If you are implementing a custom solution or block, you can use the following session logic to manage success messages:

<?php

$session = kirby()->session();
$successMessage = $session->get('form.success');

if ($successMessage) {
    $session->remove('form.success');
    snippet('email-manager/success-message');
}

How it works:

  • After a form is submitted successfully, a success message is stored in the session under form.success.
  • When the page is loaded, the message is retrieved and displayed using success-message.php.
  • The session data is cleared immediately after the message is shown.

This logic can be used in any template, whether for a standalone solution or as part of a custom block.