PHP code example of djl997 / simple-laravel-form-protection
1. Go to this page and download the library: Download djl997/simple-laravel-form-protection 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/ */
djl997 / simple-laravel-form-protection example snippets
use Djl997\SimpleLaravelFormProtection\Concerns\UsesFormSubmission;
class ContactForm extends Component
{
use UsesFormSubmission;
protected string $form_key = 'contact';
public function mount(): void
{
$this->mountMeta();
}
public function submit()
{
$this->validate();
$submission = $this->createFormSubmission([
'name' => $this->name,
'email' => $this->email,
'message' => $this->message,
]);
if (! $submission->is_spam) {
Mail::to('[email protected]')->send(new ContactFormSubmitted(...));
}
}
}
use Djl997\SimpleLaravelFormProtection\Facades\FormProtection;
use Djl997\SimpleLaravelFormProtection\Scoring\SpamScorer;
public function store(Request $request)
{
$data = $request->validate([
'name' => ['ssage($data['message']);
$submission = FormProtection::record($request, 'contact', $data, $content_score);
if (! $submission->is_spam) {
Mail::to('[email protected]')->send(new ContactFormSubmitted($submission));
}
return back()->with('status', 'Bedankt voor je bericht!');
}
public function calculateContentScore(int $content_score = 0): int
{
$content_score = $this->scoreEmail($this->email, $content_score);
$content_score = $this->scorePhone($this->phone, $content_score);
return $this->scoreMessage($this->message, $content_score);
}
public function spamScoreThreshold(): int
{
return 4;
}