A Drag & Drop Forms Builder based on LUYA CMS Blocks.
Available forms module block extensions:
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
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.
....
}
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']);
}
}
Refresh message files:
./vendor/bin/luya message msgconfig.php