nstcactus/craft-contact-form-settings-module 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nstcactus/craft-contact-form-settings-module

Composer 安装命令:

composer require nstcactus/craft-contact-form-settings-module

包简介

A Craft module to manage multiple contact forms using the contact-form & contact-form-extensions plugins

README 文档

README

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

  1. Install the composer module : composer require nstcactus/craft-contact-form-settings-module

  2. Add the contents of the app.php file to your config/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:

    return [
        'modules' => [
            'contact-form-settings-module' => [
                'class' => \nstcactus\craftcms\modules\contactFormSettings\ContactFormSettingsModule::class,
                'components' => [
                    // More on this below
                ],
            ],
        ],
        'bootstrap' => ['contact-form-settings-module'],
    ];

Add a form

  1. Create a form class that extends \modules\contactFormSettings\forms\AbstractContactForm. This class will describe the settings of your form.

  2. Register this form class in the config/app.php file: add an entry in the components array of the module where the key is the form name and the value is a reference to the form class.

    Example:

    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'],
    ];
  3. 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:

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.'));
    }
}

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 the getContactFormSetting() method

  • set it using the contact-form-extensions override mechanism in either the beforeValidateSubmission() or the afterValidateSubmission() method. Example:

    public function beforeValidateSubmission(ModelEvent $e): void
    {
      parent::beforeValidateSubmission($e);
      $submission = $e->sender->message['toEmail'] = Craft::$app->getSecurity()->hashData($subject->contactSubjectRecipient);
    }

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:

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'] ?? ''
        ));
    }
}

nstcactus/craft-contact-form-settings-module 适用场景与选型建议

nstcactus/craft-contact-form-settings-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 568 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 nstcactus/craft-contact-form-settings-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nstcactus/craft-contact-form-settings-module 我们能提供哪些服务?
定制开发 / 二次开发

基于 nstcactus/craft-contact-form-settings-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 568
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-10