Download the PHP package nstcactus/craft-contact-form-settings-module without Composer
On this page you can find all versions of the php package nstcactus/craft-contact-form-settings-module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nstcactus/craft-contact-form-settings-module
More information about nstcactus/craft-contact-form-settings-module
Files in nstcactus/craft-contact-form-settings-module
Package craft-contact-form-settings-module
Short Description A Craft module to manage multiple contact forms using the contact-form & contact-form-extensions plugins
License MIT
Informations about the package craft-contact-form-settings-module
ContactFormSettings module for Craft CMS
This module helps to manage multiple sets of settings form the Craft contact-form
& contact-form-extensions
plugins.
Requirements
This module requires:
- PHP 7.1 or later
- Craft CMS 3, 4 or 5
- contact-form plugin 2.2 or later
- [optional] contact-form-extensions plugin 1.2.1 or later
Installation
-
Install the composer module :
composer require nstcactus/craft-contact-form-settings-module
-
Add the contents of the
app.php
file to yourconfig/app.php
(or just copy it there if it does not exist). This ensures that your module will get loaded for each request.The file might look something like this:
Add a form
-
Create a form class that extends
\modules\contactFormSettings\forms\AbstractContactForm
. This class will describe the settings of your form. -
Register this form class in the
config/app.php
file: add an entry in thecomponents
array of the module where the key is the form name and the value is a reference to the form class.Example:
- Add the following in the template of the form, inside the
<form>
element:{{ formNameInput('contact') }}
Form settings
Plugin settings override
Each form setting class must implement the getContactFormConfiguration()
& getContactFormExtensionsConfiguration()
methods. They expect a return value that is a settings array, just like what would be set in the
config/contact-form.php
& contact-form-extensions.php
.
Custom validation
Custom validation rules should be defined by overriding the afterValidateSubmission()
method. Here you can add
validation errors on the Submission
instance (available in $e->sender
) like so:
``
FAQ
How do I safely let the use pick from a list of subjects?
When the subject is selected by the user in a <select>
element for example, the recommended approach is
How do I set the recipient dynamically?
To set the recipient dynamically, you can either:
- set it in the
toEmail
property in the array return from thegetContactFormSetting()
method -
set it using the
contact-form-extensions
override mechanism in either thebeforeValidateSubmission()
or theafterValidateSubmission()
method. Example:``
How do I use separate fields for first name & last name?
When using separate first & last name field as opposed to a single fromName
field, make sure to actually set the
fromName
property of the Submission
instance in the afterValidateSubmission()
method.
This will improve submission index in the control panel.
Example:
``