10-04-2026
This commit is contained in:
parent
4d6b4930b2
commit
4bb89aad8c
836 changed files with 52961 additions and 5950 deletions
100
app/Livewire/Web/Components/Sections/ImmobilienContactForm.php
Normal file
100
app/Livewire/Web/Components/Sections/ImmobilienContactForm.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Web\Components\Sections;
|
||||
|
||||
use Acme\ContactForm\ContactFormService;
|
||||
use Acme\ContactForm\SpamDetector;
|
||||
use Livewire\Component;
|
||||
|
||||
class ImmobilienContactForm extends Component
|
||||
{
|
||||
public string $projectSlug = '';
|
||||
|
||||
public string $projectTitle = '';
|
||||
|
||||
/** @var array<string, string> */
|
||||
public array $interestOptions = [];
|
||||
|
||||
public string $interest = '';
|
||||
|
||||
public string $firstName = '';
|
||||
|
||||
public string $lastName = '';
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $phone = '';
|
||||
|
||||
public string $message = '';
|
||||
|
||||
public bool $privacy = false;
|
||||
|
||||
public bool $success = false;
|
||||
|
||||
/** @var string Hidden honeypot field */
|
||||
public string $website = '';
|
||||
|
||||
public ?int $formLoadedAt = null;
|
||||
|
||||
/**
|
||||
* @param array<string, string> $interestOptions
|
||||
*/
|
||||
public function mount(string $projectSlug = '', string $projectTitle = '', array $interestOptions = []): void
|
||||
{
|
||||
$this->projectSlug = $projectSlug;
|
||||
$this->projectTitle = $projectTitle;
|
||||
$this->interestOptions = $interestOptions;
|
||||
$this->formLoadedAt = time();
|
||||
}
|
||||
|
||||
public function submit(ContactFormService $service): void
|
||||
{
|
||||
$this->validate([
|
||||
'firstName' => ['required', 'string', 'max:255'],
|
||||
'lastName' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email:rfc', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:80'],
|
||||
'interest' => ['nullable', 'string', 'max:255'],
|
||||
'message' => ['nullable', 'string', 'max:2000'],
|
||||
'privacy' => ['accepted'],
|
||||
'website' => ['nullable', 'string', 'max:0'],
|
||||
]);
|
||||
|
||||
$spamDetector = SpamDetector::fromConfig();
|
||||
$payload = [
|
||||
'project' => $this->projectSlug,
|
||||
'project_title' => $this->projectTitle,
|
||||
'interest' => $this->interest,
|
||||
'first_name' => $this->firstName,
|
||||
'last_name' => $this->lastName,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->phone,
|
||||
'message' => $this->message,
|
||||
'website' => $this->website,
|
||||
'ip' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
'is_spam' => false,
|
||||
];
|
||||
|
||||
$payload['is_spam'] = $spamDetector->detect($payload, $this->formLoadedAt);
|
||||
|
||||
$subject = 'Immobilien-Anfrage: '.($this->projectTitle ?: $this->projectSlug);
|
||||
$service->handle($payload, $subject, 'immobilien-contact-form');
|
||||
|
||||
$this->success = true;
|
||||
$this->interest = '';
|
||||
$this->firstName = '';
|
||||
$this->lastName = '';
|
||||
$this->email = '';
|
||||
$this->phone = '';
|
||||
$this->message = '';
|
||||
$this->privacy = false;
|
||||
$this->website = '';
|
||||
$this->formLoadedAt = time();
|
||||
}
|
||||
|
||||
public function render(): \Illuminate\View\View
|
||||
{
|
||||
return view('livewire.web.components.sections.immobilien-contact-form');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue