Unsure which method to use to show CreateContactForm on url TLD/contact

Hey Everyone, My 1st post here and am quite new to Filament, although I've read docs several times. * I have 2 panels; public (/) & admin (/admin). I've created ContactForm resource to work with the ContactForm model. * If I just fill in a contact form from the admin panel using the CreateContactForm::class, everything works fine. * I also have a custom page 'contact' set up within the 'public' form, so that it appears at /contact * I have a full site working in Laravel/Vue3, but I'm trying to convert it to Filament * I've searched the previous posts but not initially able to find an answer * I'm PHP/Vue is my weapon of choice, but I'm looking at/trying to move from Vue to Livewire (I'm quite new to using Livewire) But, what's the best way to get the get the contact form to display in the /contact page? 1. Is it best to get the form working in the custom contact page using the instructions under Form Builder > Adding a form to a Livewire component 2. Change the url/route of CreateContactForm::class using something like getUrl() 3. Not use Filament for the customer facing public side 4. Anything else you can think of I've tried both 1 & 2, but have run into problems with both of them, so I'm basically looking for advise. A very disjointed post, I appreciate, but any help would be much appreciated. John
Solution:
I managed to sort it. I ended up with the contact page at localhost/contact (option 1), with the following inclusions in the contact page ```php protected function mutateFormDataBeforeCreate(array $data): array { if (isset($data['user_id'])) {...
Jump to solution
2 Replies
GrandadEvans
GrandadEvansOP10mo ago
Update: OK, ignore option 2 from above, as I misunderstood the usage or getUrl()
Solution
GrandadEvans
GrandadEvans10mo ago
I managed to sort it. I ended up with the contact page at localhost/contact (option 1), with the following inclusions in the contact page
protected function mutateFormDataBeforeCreate(array $data): array
{
if (isset($data['user_id'])) {
$user = Auth::user();
$data['name'] = $user->name;
$data['email'] = $user->email;
$data['tel'] = $user->tel;
} else {
$data['user_id'] = null;
}
return $data;
}

protected function getRedirectUrl(): string
{
return url(route('contact.confirmation'));
}
public function create(): void
{
try {
$data = $this->form->getState();

$data = $this->mutateFormDataBeforeCreate($data);

$this->record = ContactForm::create($data);

// $this->form->model($this->getRecord())->saveRelationships();
} catch (Halt $exception) {
return;
}

Notification::make()
->title('Message Sent')
->success()
->send();

$redirectUrl = '/contact-confirmation';

$this->redirect(
$redirectUrl,
navigate: FilamentView::hasSpaMode() && str($redirectUrl)->startsWith(request()->root())
);
}
protected function mutateFormDataBeforeCreate(array $data): array
{
if (isset($data['user_id'])) {
$user = Auth::user();
$data['name'] = $user->name;
$data['email'] = $user->email;
$data['tel'] = $user->tel;
} else {
$data['user_id'] = null;
}
return $data;
}

protected function getRedirectUrl(): string
{
return url(route('contact.confirmation'));
}
public function create(): void
{
try {
$data = $this->form->getState();

$data = $this->mutateFormDataBeforeCreate($data);

$this->record = ContactForm::create($data);

// $this->form->model($this->getRecord())->saveRelationships();
} catch (Halt $exception) {
return;
}

Notification::make()
->title('Message Sent')
->success()
->send();

$redirectUrl = '/contact-confirmation';

$this->redirect(
$redirectUrl,
navigate: FilamentView::hasSpaMode() && str($redirectUrl)->startsWith(request()->root())
);
}
Want results from more Discord servers?
Add your server