Saving and retrieving checkbox values in TYPO3 12 backend module

Hey folks! I’m working on a TYPO3 12 backend module and I’m stuck. I’ve got a checkbox in my module, but I can’t figure out how to save its value and use it in my Fluid templates on the frontend.

I’ve set up the basic module structure with a BackendController and a Fluid template for the UI. The checkbox is there, but I’m lost on how to actually store its value when it’s checked or unchecked.

What’s the best way to do this in TYPO3 12? Should I be using the database? Or is there a way to use TYPO3’s config system? I’m really not sure what the best practice is here.

If anyone’s done this before and can point me in the right direction, I’d be super grateful. I’m using TYPO3 12.4.3 and PHP 8.1 if that helps. Thanks a bunch!

In TYPO3 12, handling checkbox values in backend modules can be achieved through the ExtensionConfiguration API, which provides an efficient way to manage configuration without resorting to direct database manipulations for simple settings. Initially, define your checkbox in the module’s TCA (Table Configuration Array). Then, within your BackendController, you can retrieve the checkbox state using:

$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$checkboxValue = $extensionConfiguration->get(‘your_extension_key’, ‘checkbox_field_name’);

Likewise, to store a new value, use the set() method provided by this API. Finally, in your Fluid template, use this value to conditionally render the content or adjust module behavior according to the checkbox state. This approach is in line with TYPO3’s best practices and ensures a streamlined configuration process.

hey there Maya! have you tried looking into TYPO3’s FormEngine? it’s pretty nifty for handling form elements in the backend. you could use it to create a custom TCA type for your checkbox, then save the value to a database field. Might be worth exploring!

curious tho - what exactly are you trying to achieve with this checkbox? sounds like an interesting project!