Concrete form in package

User
HOw use concrete standard form in custom package
Assistant
In Concrete CMS (v9+), if you want to use the **standard Concrete form system** inside your **custom package**, you don’t need to reinvent fields or HTML. Concrete gives you a helper service called `form` and also integrates with Symfony form-style helpers.

Here’s a step-by-step guide 👇

### 1. Load the Form Helper
In your controller or view:

$form = Core::make('helper/form');

### 2. Use in a Package Dashboard Page (Example)
If you have a dashboard single page inside your package (say `/dashboard/shopping_feed/settings`), in your `view.php` you can do:

<?php defined('C5_EXECUTE') or die("Access Denied."); ?>

<div class="ccm-dashboard-content-full">
    <h2><?= t("Shopping Feed Settings"); ?></h2>

    <form method="post" action="<?= $view->action('save_settings') ?>">
        <div class="form-group">
            <?= $form->label('feedName', t('Feed Name')); ?>
            <?= $form->text('feedName', $feedName ?? ''); ?>
        </div>

        <div class="form-group">
            <?= $form->label('status', t('Enable Feed')); ?>
            <?= $form->checkbox('status', 1, $status ?? false); ?>
        </div>

        <div class="form-group">
            <?= $form->label('feedType', t('Feed Type')); ?>
            <?= $form->select('feedType', [
                'google' => t('Google Merchant'),
                'facebook' => t('Facebook Catalog')
            ], $feedType ?? 'google'); ?>
        </div>

        <div class="form-group">
            <?= $form->submit('submit', t('Save'), ['class' => 'btn btn-primary']); ?>
        </div>
    </form>
</div>

### 3. Handle Submission in Your Controller
In `controllers/single_page/dashboard/shopping_feed/settings.php`:

<?php
namespace ConcretePackageShoppingFeedManagerControllerSinglePageDashboardShoppingFeed;

use ConcreteCorePageControllerDashboardPageController;

class Settings extends DashboardPageController
{
    public function save_settings()
    {
        if ($this->token->validate('save_settings')) {
            $feedName = $this->request->request->get('feedName');
            $status = $this->request->request->get('status') ? 1 : 0;
            $feedType = $this->request->request->get('feedType');

            // Save to config, DB, etc.
            $this->flash('success', t('Settings saved.'));
            return $this->redirect($this->action(''));
        } else {
            $this->error->add($this->token->getErrorMessage());
        }
    }
}

Make sure to include a token field in your form:

<?= $this->controller->token->output('save_settings'); ?>

### 4. Concrete Standard Look & Feel
– Use `form-group` + Concrete’s Bootstrap 5 classes for spacing/layout.
– Submit button should use `btn btn-primary` to look native.
– Wrap your content in “ or “ for dashboard consistency.

✅ This way your custom package uses **Concrete standard form system** (same as core dashboard pages) and is **Marketplace-compatible**.

Do you want me to also show you how to integrate this with **Doctrine ORM entity save** (instead of just config values)?

Leave a Comment

Your email address will not be published. Required fields are marked *