The built-in handler types (smtp, file, webhook) cover most
needs. For anything more custom, use the webhook handler type to
POST form data to a URL you control - a small CGI script that receives
JSON and performs your action.
This page documents the JSON contract so you can write those scripts.
A helper must:
Status: and Content-Type: headersJSON object with field names as keys. Internal fields (_form, _ts,
_tk, _hp) are excluded - only user-submitted fields are sent.
{
"name": "John Smith",
"email": "john@example.com",
"message": "Hello there"
}
Status: 200 OK
Content-Type: application/json
{"ok":1}
Status: 500 Internal Server Error
Content-Type: application/json
{"ok":0,"error":"Description of error"}
#!/usr/bin/perl
use strict;
use warnings;
use JSON::PP qw(encode_json decode_json);
eval {
my $json = do { local $/; <STDIN> };
my $form = decode_json($json);
# --- Your logic here ---
# $form->{name}, $form->{email}, etc.
print "Status: 200 OK\r\n";
print "Content-Type: application/json\r\n\r\n";
print encode_json({ ok => 1 });
};
if ($@) {
warn "my-helper: $@";
print "Status: 500 Internal Server Error\r\n";
print "Content-Type: application/json\r\n\r\n";
print encode_json({ ok => 0, error => "$@" });
}
Add a webhook handler entry in lazysite/forms/handlers.conf:
handlers:
- id: my-helper
type: webhook
name: My custom helper
enabled: true
url: http://localhost/cgi-bin/my-helper.pl
format: json
Reference it from the form's .conf file:
targets:
- handler: my-helper
Use format: json for the contract documented on this page. Use
format: slack for a Slack-compatible {"text": "..."} body.
echo '{"name":"Test","email":"test@test.com"}' | \
DOCUMENT_ROOT=/path/to/public_html \
perl cgi-bin/my-helper.pl
open(my $fh, '>>', '/var/log/form-submissions.log');
print $fh encode_json($form) . "\n";
close($fh);
use LWP::UserAgent;
my $ua = LWP::UserAgent->new(timeout => 10);
$ua->post('https://hooks.example.com/endpoint',
Content_Type => 'application/json',
Content => encode_json($form));