2017 © Pedro Peláez
 

craft-plugin craft3-forms

Craft 3 formulieren

image

dolphiq/craft3-forms

Craft 3 formulieren

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 2 Open issues
  • 3 Versions
  • 91 % Grown

The README.md

Form plugin for Craft CMS 3.x

Currently the project is DISCONTINUED. However, feel free to fork it and continue its development!

Craft CMS 3 is build on top of the Yii 2 Framework. This plugin makes it possible to use forms the way the Yii 2 Framework offers. This includes: - Easy out of the box client and server side validation with use of rules in a model. - Assign field labels in your model to use them in multiple areas., (*1)

Next to this Yii 2 Framework logic, we added: - Easily enable/disable the form in the settings. - Easily enable/disable logging form entries into the database in the settings. - Control the recipient and subject of the contact requests e-mails in the plugin settings per form. - Twig extensions, form examples and E-mail examples., (*2)

Note: This plugin may become a paid add-on when the Craft Plugin store becomes available., (*3)

Requirements

  • Craft 3.0 (beta 28)+
  • PHP 7.0+

Installation

  1. Install with Composer, (*4)

    composer require dolphiq/craft3-forms, (*5)

  2. Install plugin in the Craft Control Panel under Settings > Plugins, (*6)

  3. Add a new directory forms to the root directory of your craft project (next to your config and templates directory) or copy the forms directory from the examples folder in the plugin directory, (*7)

Directory structure

Below you will find an example directory structure for a contact and a vacancy form, (*8)

As you can see each form has its own directory. The minimum files are the files in the contact directory. When using every functionallity of this plugin you have as much files as you see in the vacancy directory., (*9)

forms/
    contact/
        contactForm.php
        contactView.php
    vacancy/
        vacancyForm.php
        vacancyView.php
        vacancyMailOwner.php
        vacancyCustomerMail.php
        vacancyThanks.php
    thanks.php       

Creating a new form

Lets say that we are going to create a contact form., (*10)

  1. Create a directory with the name of your form inside the forms directory. This name will be your form handle later on. In this case it will be named contact
  2. Inside this directory create two files:, (*11)

    • contactForm.php This file is a model that defines the fields and rules for the form. The name consists of the handle appended with Form.php., (*12)

      This file is a model as descriped on: http://www.yiiframework.com/doc-2.0/guide-start-forms.html#creating-model Make sure the class extends the Form model from the plugin and uses the app\forms namespace, if you don't then the plugin won't work., (*13)

      Example contactForm.php
      namespace app\forms;
      
      use Craft;
      use plugins\dolphiq\form\models\Form;
      
      class contactForm extends Form {
      
       public $firstname = "";
       public $lastname = "";
       public $phone = "";
       public $email = "";
       public $message = "";
      
       public function rules()
       {
           return [
               [['firstname', 'lastname', 'email', 'message'], 'required'],
               ['email', 'email'],
               ['phone', 'safe']
           ];
       }
      
       public function attributeLabels()
       {
           return [
               'firstname' => Craft::t('site', 'Firstname'),
               'lastname' => Craft::t('site', 'Lastname'),
               'phone' => Craft::t('site', 'Phone'),
               'email' => Craft::t('site', 'Email'),
               'message' => Craft::t('site', 'Message'),
           ];
       }
      }
      
    • contactView.php This file is a view with which you can display your form. The name consists of the handle appended with View.php., (*14)

      The file is a view file as descriped on: http://www.yiiframework.com/doc-2.0/guide-start-forms.html#creating-views It is important to leave the action of the activeform and the id of the pjax widget id unchanged, else your form won't work., (*15)

      Example contactView.php
       false, 'id' => 'pjax-'.$handle]);
      
          // Start active form
          $form = ActiveForm::begin([
              'action' => \craft\helpers\UrlHelper::actionUrl('dolphiq-craft3-forms/main/index', ['handle' => $handle]),
              'method' => 'POST',
              'options' => [
                  'data-pjax' => true,
              ],
          ]);
      
          ?>
      
      = $form->field($model, 'firstname')->textInput(); ?>
      = $form->field($model, 'lastname')->textInput(); ?>
      = $form->field($model, 'phone')->textInput(); ?>
      = $form->field($model, 'email')->textInput(); ?>
      
      = $form->field($model, 'message')->textarea(); ?>
      
      
      
      
  3. In your template you can now use the form by using the tag the following tag. Instead of contact you fill in the handle of your form., (*16)

    {{ dolphiqForm('contact') }}
    

Thank you message

When the form is submitted and validated correctly it will be replaced with a thank you message. There are two types of thank you messages:, (*17)

  1. Default thank you message., (*18)

    The plugin comes with a default thank you message. You can overwrite this message by creating a thanks.php file in the forms/ directory. This will then be your default thank you message that is used for all your forms. You can use the form model here to personalize the thank you message., (*19)

    Example of a default thank you message
    <p>Thank you! We will contact you soon.</p>
    
  2. A custom, per form, thank you message, (*20)

    You can create a thank you message per form so it won't use the default thank you message. This is extra usefull if you want to personalize the thank you message by using the form model., (*21)

    Example of a customer, per form, thank you message

    ```php , (*22)

Thank you = $model->firstname ?>, we will contact you soon, (*23)

```

Mails

You can enable the plugin to send an email to the form owner and to the person who filled in the form. To do this you can create two files:, (*24)

  1. contactMailOwner.php This file contains the email that will be send to the owner of the form., (*25)

    You can use the $model variable to get attributes from the filled in form., (*26)

    Example
    
    
    
    

    A contact request has been filled in

    We received the following details:
    = DetailView::widget([ 'model' => $model, 'attributes' => [ 'firstname', 'lastname', 'email', 'phone', 'message:ntext' ] ]); ?> , (*27)

  2. contactMailCustomer.php This file contains the email that will be send to the person who filled in the form (if there is an email attribute available en it is filled in)., (*28)

    You can use the $model variable to get attributes from the filled in form. This way you can personalize the email., (*29)

    
    
    
    

    Thank you for your message = $model->lastname; ?>

    We will contact you as soon as possible , (*30)

The two mails will be wrapped with a mail layout that is defined in the plugin folder. You can not change this., (*31)

CP Settings

In the Controlpanel you can set the settings per form. You can set the following options per form: * Enabled When disabled the form will not be shown * Logging When enabled the results from the form will be logged into the database * Owner Mail This is the email that will be send when the form has been filled in. You can fill in the following options: * Mail to adress The emailadress to which the email will be send * Mail subject The subject of the email that will be send to above emailaddress * Customer Mail This is the email that will be send to the person who filled in the form. This only works when the form contains the email attribute so the person that fills in the form can fill in his emailadress. You can fill in the following option: * Mail subject The subject of the email that will be send to the customers emailaddress., (*32)

Contributors & Developers

Lucas Weijers - info@dolphiq.nl Brought to you by Dolphiq, (*33)

The Versions

26/06 2018

dev-development

dev-development

Craft 3 formulieren

  Sources   Download

MIT

The Requires

 

plugin yii2 form cms yii forms craftcms craft-plugin craft craft3

26/06 2018

dev-master

9999999-dev

Craft 3 formulieren

  Sources   Download

MIT

The Requires

 

plugin yii2 form cms yii forms craftcms craft-plugin craft craft3

16/10 2017

1.0.0

1.0.0.0

Craft 3 formulieren

  Sources   Download

MIT

The Requires

 

plugin yii2 form cms yii forms craftcms craft-plugin craft craft3