/luya-module-forms

Generate Forms with CMS Blocks

Primary LanguagePHP

LUYA Logo

LUYA CMS Form Builder

LUYA Tests

Generate forms with LUYA CMS Blocks

Installation

Install the extension through composer:

composer require luyadev/luya-module-forms

Add the module to the config

'modules' => [
  'forms' => [
    'class' => 'luya\forms\Module',
  ]
]

Run the migrate command

./luya migrate

Run the import command afterwards:

./luya import

Create Custom Form Field Blocks

The default blocks may not suit your needs, therefore its possible to create your own from input block:

class MyDropDownBlock extends PhpBlock
{
    use FieldBlockTrait;
    
    public function name()
    {
        return 'Dropdown';
    }

    public function admin()
    {
        return '<p>My Dropdown {{vars.label}}</p>';
    }

    public function frontend()
    {
        Yii::$app->forms->autoConfigureAttribute(
            $this->getVarValue($this->varAttribute),
            $this->getVarValue($this->varRule, $this->defaultRule), 
            $this->getVarValue($this->varIsRequired),
            $this->getVarValue($this->varLabel),
            $this->getVarValue($this->varHint)
        );

        // Use all possible options with ActiveField or use the HtmlHelper
        return Yii::$app->forms->form->field(Yii::$app->forms->model, $this->getVarValue($this->varAttribute))
            ->dropDownList([1 => 'Foo', 2 => 'Bar']);
    }
}

Development

Refresh message files:

./vendor/bin/luya message msgconfig.php