I'm currently developing a custom backend module in TYPO3 12 and want to store a checkbox value so that I can retrieve it in the frontend (Fluid template).
I successfully created the backend module using this video: ▶
However, the video (and all other resources I found) do not explain how to store form inputs and retrieve them later.
My current setup:
BackendController.php
<?php
namespace LjBarrierefrei\Controller;
use TYPO3\CMS\Backend\Attribute\AsController;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Psr\Http\Message\ResponseInterface;
#[AsController]
final class BackendController extends ActionController
{
public function __construct(
protected readonly ModuleTemplateFactory $moduleTemplateFactory,
) {
}
public function indexAction(): ResponseInterface
{
$this->view->assign('someVar', 'someContent');
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
}
}
Fluid Template Index.html (Backend module UI)
<div class="m-lg-5 border p-4">
<h1>Barrierefrei Einstellungen</h1>
<p>Hier können Sie die Moduleinstellungen konfigurieren.!!!!</p>
<f:form action="save">
<label>
<f:form.checkbox name="enable_barrierefrei" value="1" checked="{enableBarrierefrei}" />
Barrierefreiheit aktivieren
</label>
<f:form.submit value="Speichern" />
</f:form>
</div>
My question:
How can I properly store the checkbox value so that: The setting is persisted after saving I can retrieve the value in the frontend (e.g., in Fluid {settings.enableBarrierFree})
I am unsure about the best way to store the checkbox value:
Should I store it in a TYPO3 database table?
Can I store it using TYPO3 configuration ($GLOBALS['TYPO3_CONF_VARS'])?
What is the best practice in TYPO3 12 backend modules for storing such settings?
If anyone has a clear explanation or example, I would really appreciate your help!