luyadev / luya-module-forms
A form builder module for LUYA CMS.
Installs: 6 429
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 4
Open Issues: 0
Type:luya-module
Requires
- luyadev/luya-module-admin: >=3.0
- luyadev/luya-module-cms: >=3.4
- yiisoft/yii2: ^2.0.35
Requires (Dev)
- luyadev/luya-testsuite: ^3.0
README
LUYA CMS Forms Builder
A Drag & Drop Forms Builder based on LUYA CMS Blocks.
Available forms module block extensions:
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 which does the database table setup:
./luya migrate
Run the import command in order to setup all the need permissions:
./luya import
Adjust Mailer Component
In order to customize the mailer component which should be taken for sending the mails, define the Forms component with the given callback.
'components' => [ //... 'forms' => [ 'class' => 'luya\forms\Forms', 'emailMessage' => function (SubmissionEmail $email, Forms $form) { // your custom mailer integration is here, ensure to return a boolean // value whether sending was successfull or not! return \Yii::$app->mailer->compose() ->setFrom(...) ->setTo($email->getRecipients()) ->setSubject($email->getSubject()) ->setTextBody($email->getBodyText()) ->setHtmlBody($email->getBodyHtml()) ->send(); } ] ]
Maybe the client would like to recieve a custom email, therefore you can extract the attribute value with $email->submission->getValueByAttribute('email_attribute_in_form')
.
'emailMessage' => function (SubmissionEmail $email, Forms $form) { return Yii::$app->mailer->compose() ->setTo($email->submission->getValueByAttribute('email')) // receives the value from the user entered data. .... }
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