PHP code example of nstcactus / craft-contact-form-settings-module
1. Go to this page and download the library: Download nstcactus/craft-contact-form-settings-module library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nstcactus / craft-contact-form-settings-module example snippets
return [
'modules' => [
'contact-form-settings-module' => [
'class' => \nstcactus\craftcms\modules\contactFormSettings\ContactFormSettingsModule::class,
'components' => [
// More on this below
],
],
],
'bootstrap' => ['contact-form-settings-module'],
];
return [
'modules' => [
'contact-form-settings-module' => [
'class' => \nstcactus\craftcms\modules\contactFormSettings\ContactFormSettingsModule::class,
'components' => [
'contact' => \project\modules\app\forms\ContactForm::class,
],
],
],
'bootstrap' => ['contact-form-settings-module'],
];
public function afterValidateSubmission(Event $e): void
{
/** @var Submission $submission */
$submission = $e->sender;
if (empty($submission->message['FirstName'])) {
$submission->addError('message.FirstName', Craft::t('site', 'This field cannot be blank.'));
}
}
public function beforeValidateSubmission(ModelEvent $e): void
{
parent::beforeValidateSubmission($e);
$submission = $e->sender->message['toEmail'] = Craft::$app->getSecurity()->hashData($subject->contactSubjectRecipient);
}
public function afterValidateSubmission(Event $e): void
{
/** @var Submission $submission */
$submission = $e->sender;
if (!empty($submission->message['FirstName']) || empty($submission->message['LastName'])) {
$submission->fromName = trim(sprintf(
'%s %s',
$submission->message['FirstName'] ?? '',
$submission->message['LastName'] ?? ''
));
}
}