silverstripe/contact-form

该软件包已被放弃,不再维护。没有建议的替代软件包。

允许您在 SilverStripe 中创建联系表单,并可选择与 Postmark 集成。与 Bootstrap Forms 模块兼容。

安装量: 1,780

依赖项: 0

建议者: 0

安全: 0

星标: 11

关注者: 9

分支: 10

开放问题: 17

语言:JavaScript

类型:silverstripe-module

dev-master 2016-06-20 20:18 UTC

This package is not auto-updated.

Last update: 2021-12-05 22:29:44 UTC


README

此模块允许您创建一个简单的联系表单并将其添加到页面类型中。由于表单的创建发生在页面控制器中,因此它具有高度的可配置性。

功能

  • Postmark 集成,以确保电子邮件可靠送达
  • Boostrap Forms 模块 集成
  • 包含用于自动 jQuery 验证的 API
  • 可以扩展您自己的垃圾邮件保护插件的垃圾邮件保护 API
  • 将失败的垃圾邮件尝试记录到数据库中,并锁定重复违规的 IP 地址

“厨房水槽”示例

<?php

public function ContactForm() {
  return ContactForm::create("ContactForm","you@example.com","You've received a new contact form!")
            ->addFields(
                TextField::create("Name","What is your name?"),
                EmailField::create("Email", "What is your email?")
            )
            // You can add fields as strings, too.
            ->addField("Your message//Textarea")
            ->setSuccessMessage("Thanks for submitting the form!")
            ->setSuccessURL($this->Link('success'))
            ->setOnBeforeSend(function($data, $form) {
                  // Do stuff here. Return false to refuse the form.
            })
            ->setEmailTemplate("MyCustomTemplate")
            ->addOmittedField("SomeField")
            ->setIntroText("Someone submitted a form. Here's the data.")
            ->addSpamProtector(
                SimpleQuestionSpamProtector::create()
                  ->addQuestion("What's the opposite of skinny?","fat")
                  ->addQuestion("Which is bigger, a lake or an ocean?","ocean")
            )
            ->render();
}

关于 ->render() 的内容

ContactForm 类实际上不是一个表单。它是一个充当 Form 对象代理管理器的对象。->render() 方法对于将表单发送到模板至关重要。

ContactFormPage

ContactForm 模块附带一个页面类型,允许您基于 CMS 中的用户输入轻松创建联系表单。ContactFormPage 类具有“收件人”地址、成功消息等字段。

要创建包含联系表单的页面,只需创建 ContactFormPage 的子类并调用父类 Form() 方法即可。

<?php

class MyContactPage extends ContactFormPage {}

class MyContactPage_Controller extends ContactFormPage_Controller {

  public function Form() {
    return parent::Form()
        ->addFields(
          TextField::create("YourName","Your name"),
          EmailField::create("Email","Your email"),
          TextareaField::create("Message","Your message")
        )
        ->render();
  }
}

设置 Postmark

只需将您的 API 密钥和确认的“来自”地址添加到 _config.php 中。

<?php

define('POSTMARKAPP_API_KEY','xxxxxxxxxxxxxxxxxxxxx');
define('POSTMARKAPP_MAIL_FROM_ADDRESS', 'me@example.com');

一旦设置这些设置,ContactForm 模块将使用 Postmark 作为其交付方法。

与 Bootstrap Forms 集成

如果您已安装 BootstrapForms 模块,则表单将自动渲染为 BootstrapForm,除非您明确指出否则,使用 ->setUseBootstrap(false)

设置默认垃圾邮件保护

您可以为每个表单设置默认的垃圾邮件保护,除非另行配置。

_config.php

<?php

ContactForm::set_default_spam_protection(array(
  	SimpleQuestionSpamProtector::create()
			->setHeading("Prove you're human by answering a simple question")
			->addQuestion("Is fire hot or cold?", "hot")
			->addQuestion("What color is a stop sign?", "red")
			->addQuestion("Is water wet or dry?","wet")
			->addQuestion("Is the world flat?", "no")
			->addQuestion("What animal says \"Meow?\"", "cat"),

		HoneyPotSpamProtector::create()
			->setName("PleaseFillThisOutYouBot")