digitaladapt / vigilant-form-kit

用于 VigilantForm 的软件开发套件。

1.4.0 2020-09-30 16:35 UTC

README

CodeFactor

vigilant-form-kit

用于 VigilantForm 的软件开发套件。

那么这是什么?

VigilantFormKit 是一个简单的库,使将表单提交推送到 VigilantForm 的实例变得容易。

那么 VigilantForm 是什么?

VigilantForm 是我试图防止垃圾表单提交进入我的客户关系管理系统(CRM)的努力。

因此,而不是直接将表单提交推送到我的 CRM,我将其推送到 VigilantForm。

VigilantForm 会根据您选择的任何评分逻辑对提交进行评分;一些示例包括

  • 检查是否通过了蜜罐测试
  • 检查表单提交的速度
  • 检查电子邮件是否有效(语法和 DNS 检查)
  • 检查电话号码是否合理
  • 检查是否填写了必填字段
  • 检查 IP 地址的来源(通过 ipstack.com)
  • 寻找不良输入,如姓名字段中的 "http://"
  • 等等

评分完成后,表单提交会被评级,您可以根据评级采取不同的自定义操作。

例如,我将高质量表单提交推送到我的 CRM,但需要审查的表单提交将发送到 Discord,并提供批准/拒绝的链接;同时,垃圾表单提交将被记录到文件中以供定期审查,垃圾邮件表单提交则被静默删除。

那么如何使用它?

首先添加库

composer require digitaladapt/vigilant-form-kit

然后将它连接到您的应用程序

use VigilantForm\Kit\VigilantFormKit;

/* once per page, setup and run the tracking */
$vigilantFormKit = new VigilantFormKit("<SERVER_URL>", "<CLIENT_ID>", "<CLIENT_SECRET>");

// optional, defaults to (new SessionBag(), "vigilantform_")
// note: for Laravel you can use $request->session().
//$vigilantFormKit->setSession($session, "<PREFIX>");

// optional, defaults to ("age", "form_sequence", "/vf-pn.js", "vf-pn")
// note: "<HONEYPOT>" and "<SEQUENCE>" must be unique form field names.
// note: "<SCRIPT_SRC>" must be a public javascript file location.
// note: "<SCRIPT_CLASS>" must be the identifier used to process the honeypot in said javascript.
$vigilantFormKit->setHoneypot("<HONEYPOT>", "<SEQUENCE>", "<SCRIPT_SRC>", "<SCRIPT_CLASS>");

// optional, defaults to (new NullLogger())
//$vigilantFormKit->setLogger($logger);

// once everything is setup, run the tracking
// if this request is a non-page (script or image) file,
// pass true to track the referral page instead.
$vigilantFormKit->trackSource();
/* once per form, add honeypot field, recommend just before submit */
echo $vigilantFormKit->generateHoneypot();
use UnexpectedValueException;

/* handle form submission */
if (!empty($_POST)) {
    try {
        // will determine if user failed the honeypot test, calculate duration, and submit to server.
        $vigilantFormKit->submitForm("<WEBSITE>", "<FORM_TITLE>", $_POST);
    } catch (UnexpectedValueException $exception) {
        // handle submitForm failure
    }
}