Forms - v1.0.0
Advanced Overview
This section covers advanced features, integrations, and customization options.
Topics
- Webhooks - Send form data to external services
- Spam Protection - Protect forms from spam and abuse
- Customization - Extend and customize the package
- Artisan Commands - Command-line tools
Advanced Features
Webhooks
Send form submissions to external services:
// config/artisanpack/forms.php
'webhooks' => [
'enabled' => true,
'url' => 'https://example.com/webhook',
'secret' => 'your-secret-key',
],
Filter Hooks
Customize behavior at runtime:
use function addFilter;
// Modify validation rules
addFilter('forms.validation_rules', function ($rules, $form) {
$rules['email'] = 'required|email|unique:users,email';
return $rules;
});
// Modify webhook payload
addFilter('forms.webhook_payload', function ($payload, $form, $submission) {
$payload['custom_field'] = 'value';
return $payload;
});
Custom Field Types
Register custom field types:
use function addFilter;
addFilter('forms.field_types', function ($types) {
$types['color-picker'] = [
'label' => 'Color Picker',
'icon' => 'palette',
'category' => 'advanced',
'view' => 'my-package::fields.color-picker',
];
return $types;
});
Event-Driven Processing
Process submissions with events:
use ArtisanPackUI\Forms\Events\FormSubmitted;
Event::listen(FormSubmitted::class, function ($event) {
// Send to CRM
CRM::createLead($event->submission->getFormData());
// Add to mailing list
Newsletter::subscribe($event->submission->getValue('email'));
});
Authorization Customization
Override default policies:
// app/Policies/CustomFormPolicy.php
class CustomFormPolicy extends FormPolicy
{
public function update(User $user, Form $form): bool
{
return $user->hasPermission('edit-forms')
|| parent::update($user, $form);
}
}
Privacy Compliance
Configure for GDPR/privacy requirements:
'privacy' => [
'submission' => [
'include_ip' => false,
'anonymize_ip' => true,
'include_user_agent' => false,
],
],
Performance Optimization
- Queue notifications and webhooks
- Configure submission retention
- Use database indexes
'notifications' => [
'queue' => 'notifications',
],
'webhooks' => [
'queue' => 'webhooks',
],
'submissions' => [
'retention_days' => 365,
],
Integration Examples
Zapier Integration
// Send to Zapier webhook
'webhooks' => [
'url' => 'https://hooks.zapier.com/hooks/catch/xxxxx/xxxxx/',
],
Slack Notifications
Event::listen(FormSubmitted::class, function ($event) {
Http::post(config('services.slack.webhook'), [
'text' => "New form submission: {$event->form->name}",
'attachments' => [[
'fields' => collect($event->submission->getFormData())
->map(fn ($v, $k) => ['title' => $k, 'value' => $v])
->values()
->toArray(),
]],
]);
});
CRM Integration
Event::listen(FormSubmitted::class, function ($event) {
if ($event->form->slug === 'contact') {
HubSpot::contacts()->create([
'email' => $event->submission->getValue('email'),
'firstname' => $event->submission->getValue('first_name'),
'lastname' => $event->submission->getValue('last_name'),
]);
}
});
Next Steps
- Webhooks - Detailed webhook documentation
- Spam Protection - Anti-spam configuration
- Customization - Customization options