1. Go to this page and download the library: Download kreatif/statamic-forms 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/ */
kreatif / statamic-forms example snippets
// Disable globally for all forms (can be overridden per form)
'disable_statamic_email' => false,
// Or per-form in handlers:
'handlers' => [
'contact_form' => [
'disable_statamic_email' => true, // This form's emails are handled by the addon
'actions' => [...]
]
]
'handlers' => [
'contact_form' => [
// Override global settings for this form
'logo_url' => env('CONTACT_FORM_LOGO_URL'),
'organization_name' => 'Your Company',
'disable_statamic_email' => true,
// Rate limiting (optional)
'rate_limit' => [
'enabled' => true,
'max_attempts' => 5,
'decay_minutes' => 60,
'by' => 'ip', // 'ip', 'email', or 'session'
],
// Define the actions to run for this form
'actions' => [
// ... actions are defined here ...
],
],
],
'handlers' => [
'inquiries' => [
'actions' => [
// This action will run, but its 'to' and 'subject' will be overridden
SendAdminNotificationAction::class => ['enabled' => true, 'to' => '[email protected]'],
],
],
],
'handlers' => [
'newsletter_signup' => [
'actions' => [
// Only the Iubenda action is defined
AddToIubendaAction::class => ['enabled' => true],
],
],
],
namespace App\Listeners;
use Kreatif\StatamicForms\Events\ActionFailed;
use Illuminate\Support\Facades\Log;
class LogFailedFormActions
{
public function handle(ActionFailed $event): void
{
Log::critical('Form action failed', [
'action' => $event->actionClass,
'form' => $event->submission->form()->handle(),
'errors' => $event->result->getErrors(),
]);
// Maybe send alert to monitoring service
// Sentry::captureMessage('Form action failed');
}
}
namespace App\FormActions;
use Kreatif\StatamicForms\Actions\BaseAction;
use Kreatif\StatamicForms\Contracts\ActionResult;
use Statamic\Forms\Submission;
class SendToCustomCrmAction extends BaseAction
{
protected function handle(Submission $submission, array $config): ActionResult
{
$apiKey = $config['api_key'] ?? env('CRM_API_KEY');
$endpoint = $config['endpoint'] ?? 'https://crm.example.com/api/contacts';
// Your custom logic here
$response = Http::post($endpoint, [
'api_key' => $apiKey,
'name' => $submission->get('name'),
'email' => $submission->get('email'),
]);
if ($response->failed()) {
return ActionResult::failure(
errors: [$response->body()],
message: 'Failed to send to CRM'
);
}
return ActionResult::success(
data: $response->json(),
message: 'Successfully sent to CRM'
);
}
public function validate(array $config): bool
{
return !empty($config['api_key'] ?? env('CRM_API_KEY'));
}
public function getPriority(): int
{
return 95; // Run after most other actions
}
}