1. Go to this page and download the library: Download digitaladapt/vigilant-form 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/ */
digitaladapt / vigilant-form example snippets
use App\Mail\SubmissionProcessed;
use App\Utilities\Discord;
use Illuminate\Support\Facades\Mail;
/* use global to access the submission */
global $submission;
/* use global to access reprocess (set to true if submissions grade was overridden by user action) */
global $reprocess;
/* use global to access details (array which scoring rules applied to the submission, may be empty) */
global $details;
$color = 'ff0000'; /* red */
$webhook = 'https://discordapp.com/api/webhooks/<YOUR_WEBHOOK_URL>';
$toEmails = [
'<YOUR_EMAIL_ADDRESS>',
];
/* notification information */
$title = $submission->type->websiteTitle();
$description = $submission->message;
$fields = $submission->fields()->scoring()->pluck('input', 'field')->toArray();
$meta = [
'timestamp' => $submission->created_at->format('D, M jS, Y \a\t g:ia'),
'ip_address ' => $submission->ipAddress->ip,
'ip_location' => "{$submission->ipAddress->country} > {$submission->ipAddress->region}",
'uuid' => $submission->uuid,
] + $submission->origins()->whereIn('field', [
'utm_source', 'utm_term', 'utm_campaign', 'utm_adgroup', 'utm_medium',
])->pluck('input', 'field')->toArray();
/* send notification via chat */
$discord = new Discord($webhook, $color);
$discord->title = $title;
$discord->description = $description;
$discord->fields = $fields;
$discord->details = $details;
$discord->meta = $meta;
$discord->send(); /* sent in real-time */
/* also queue up the email, but only if not reprocessing */
if (!$reprocess) {
$email = new SubmissionProcessed();
$email->subject = 'New Submission Arrived';
$email->title = $title;
$email->description = $description;
$email->fields = $fields;
$email->details = $details;
$email->meta = $meta;
Mail::to($toEmails)->queue($email); /* queued as separate job */
}
return true;
return [
[
// if either field contains either string, the submission will be graded as "ignore"
'name' => 'name/org has url',
'score' => 10000,
'fields' => ['full_name', 'company'],
'check' => 'contains',
'values' => ['http://', 'https://'],
],
[
// if the email field is not a valid email, the submission will be graded as "junk"
'name' => 'email is invalid',
'score' => 1000,
'fields' => ['email'],
'check' => 'email',
],
[
// if the phone field fails the regular expression, the submission will be graded as "review"
// this regexp assumes phone is unformatted and is a 10 digit North American phone number.
// see: https://en.wikipedia.org/wiki/North_American_Numbering_Plan
'name' => 'phone is invalid',
'score' => 100,
'fields' => ['phone'],
'check' => 'not_regexp',
'values' => '^[2-9][0-9]{2}[2-9][0-9]{6}$',
],
[
// if any field is empty, the submission will be graded as "quality"
'name' => 'a field was left empty',
'score' => 10,
'fields' => true, /* all fields (including property "message") */
'check' => 'is_empty',
],
// if a submission passes all of these rules it will be graded as "perfect"
// it is also possible to improve the score with rules that improve the score
[
// if the ip geo-location country is USA, the submission may be upgraded from "quality" back to "perfect"
'name' => '[positive] ip_address country is USA',
'score' => -10,
'property' => 'ipAddress.country',
'check' => 'contains',
'values' => ['United States'],
],
// it is also possible to limit the maximum score
[
// if form submission seems to have originated from paid marketing, the submission may be upgraded
// from "review"/"quality" to "perfec" and disallow grades of "ignore" and "junk".
'name' => '[positive] has utm_source',
'score' => -100,
'property' => 'hasUtmSource',
'check' => 'is_bool',
'values' => true,
'limit' => 999,
],
];
global $submission; // quality Submission just pushed into CRM
$record = ['id' => '<EXTERNAL_UUID>', /* data from CRM, including "id", among other things */ ];
/* find account, so we can store extra information into our database */
if (!$submission->account) {
$account = Account::firstOrCreate(['external_key' => $record['id']]);
$submission->account()->associate($account);
$submission->save();
} else {
$account = $submission->account;
}
/* store extra information into our database */
foreach ($record as $key => $value) {
$account->setField($key, $value);
}
/* mark the submission as externally synced */
$submission->synced = true;
$submission->save();