2017 © Pedro Peláez
 

luya-module luya-module-contactform

This module provides a very fast and secure way to create customizable contact forms.

image

luyadev/luya-module-contactform

This module provides a very fast and secure way to create customizable contact forms.

  • Monday, June 4, 2018
  • by nadar
  • Repository
  • 5 Watchers
  • 0 Stars
  • 2,696 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 11 Versions
  • 8 % Grown

The README.md

LUYA Logo , (*1)

Contactform Module

Tests Maintainability Test Coverage Total Downloads, (*2)

This module provides a very fast and secure way to create customizable contact forms., (*3)

Installation

Require the contact module via composer, (*4)

composer require luyadev/luya-module-contactform

add the contact form module to your config:, (*5)

'modules' => [
    // ...
    'contactform' => [
        'class' => 'luya\contactform\Module',
        'useAppViewPath' => true, // When enabled the views will be looked up in the @app/views folder, otherwise the views shipped with the module will be used.
        'mailTitle' => 'Contact Form',
        'attributes' => [
            'name', 'email', 'street', 'city', 'tel', 'message',
        ],
        'rules' => [
            [['name', 'email', 'street', 'city', 'message'], 'required'],
            ['email', 'email'],
        ],
        'recipients' => [
            'admin@example.com',
        ],
    ],  
    // ...
],

To defined the attribute labels you can configure the module as followed:, (*6)

'attributeLabels' => [
    'email' => 'E-Mail',
],

By default LUYA will wrap the value into the Yii::t('app', $value) functions so you are able to translate the attributes labels. The above exmaple would look like this Yii::t('app', 'E-Mail')., (*7)

Integrate the Module

In order to use the module inside the LUYA CMS, just pick the Module Block and drag the block into the page. After droped the block edit the module block and picke the contactform module. This will then maybe throw an exception that there is no view file. In order to create the view file follow the next section., (*8)

View Files

Typically view files are located in views folder of your project root, create the view file for the corresponding model data at views/contactform/default/index.php with the following content:, (*9)


session->getFlash($this->context::CONTACTFORM_SUCCESS_FLASH)): ?>
    <div class="alert alert-success">The form has been submitted successfully.</div>

    <?php $form = ActiveForm::begin(); ?>
    <?= $form->field($model, 'name'); ?>
    <?= $form->field($model, 'email'); ?>
    <?= $form->field($model, 'street'); ?>
    <?= $form->field($model, 'city'); ?>
    <?= $form->field($model, 'tel'); ?>
    <?= $form->field($model, 'message')->textarea(); ?>
    <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
    <?php ActiveForm::end(); ?>

when the form validation success the variable $success will be true, in addition a Yii2 flash mesage Yii::$app->session->setFlash('contactform_success') with the key-name contactform_success will be set., (*10)

In order to ensure a form is only submited once use the LUYA Core SubmitButtonWidget., (*11)

SubmitButtonWidget::widget(['label' => 'Send', 'pushed' => 'Sending...', 'activeForm' => $form, 'options' => ['class' => 'btn btn-primary']]);

Tip: In order to style required fields with asterisks, you can use the following CSS:, (*12)

div.required label.control-label:after {
   content: " *";
   color: red;
}

Trigger after success

You can define a anonmys function which will be trigger after success, the first parameter of the function can be the model which will be assigne [[\luya\base\DynamicModel]]. Example callback:, (*13)

'modules' => [
    // ...
    'contactform' => [
        // ...
        'callback' => function($model) {
            // insert the name of each contact form into `contact_form_requests` table:
            Yii::$app->db->createCommand()->insert('contact_form_requests', ['name' => $model->name])->execute();
        }
    ],
];

Ordering fields in email

You can oder the fields in the mail wich will be send to the contact form recipient. This could be put before the rules in the contact form config., (*14)

For short and small forms this notation could be used as well:, (*15)

'modules' => [
    // ...
    'contactform' => [
        // ...
        'detailViewAttributes' => ['name', 'newsletter:bool', 'city', 'message:text:Label for Message'],    
       // ...
    ],
];

For long and complex form we would recommend this notation:, (*16)

'modules' => [
    // ...
    'contactform' => [
        // ...
        'detailViewAttributes' => [
            ['attribute' => 'name'],
            ['attribute' => 'email'],
            ['attribute' => 'newsletter:bool'],
            ['attribute' => 'city:integer'],
            ['attribute' => 'message'],
        ],       
       // ...
    ],
];

Advanced configuration

attribte example
mailTitle The mail title is also known as the mail subject
mailText This is a message which can be used as intro for the mail body. Markdown parsing is enabled by default.
sendToUserEmail If enabled, the mail will also be sent to the user who has submitted the form, configure the property with the mail field from the model.
callback An anyonymus function find the model argument in order to trigger custom functions.

The Versions

04/06 2018

dev-master

9999999-dev http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

04/06 2018

1.0.8.1

1.0.8.1 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

22/05 2018

1.0.8

1.0.8.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

24/01 2018

1.0.7

1.0.7.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

02/01 2018

1.0.6

1.0.6.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

28/11 2017

1.0.5

1.0.5.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

01/11 2017

1.0.4

1.0.4.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

25/05 2017

1.0.3

1.0.3.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

04/05 2017

1.0.2

1.0.2.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

The Development Requires

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

03/05 2017

1.0.1

1.0.1.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form

25/03 2017

1.0.0

1.0.0.0 http://luya.io

This module provides a very fast and secure way to create customizable contact forms.

  Sources   Download

MIT

php yii2 form module cms yii contact luya luya-module yii2form dynamicformbuilder yii2-form