Saving forms data to resource

I'm kind of lost. I made a form outside filament and placed it on the landing page. How do I save it in a filament resource when the user hits submit? ContactForm.php
<?php

namespace App\Livewire;

...

class ContactForm extends Component implements HasForms
{
use InteractsWithForms;

public $email;
public $first_name;
public $last_name;
public $phone;
public $message;
public $comm_method;

protected function getFormSchema(): array
{
return [
Grid::make(2)
->schema([
TextInput::make('first_name')->required(),
TextInput::make('last_name')->required(),
TextInput::make('email')->required(),
TextInput::make('phone'),
Textarea::make('message')
->rows(5)
->cols(20)
->columnSpan('full')
->maxLength(4000),
Radio::make('comm_method')
->label("Preferred Communication Method")
->options([
'email' => 'Email',
'messenger' => 'Messenger',
'viber' => 'Viber',
'whatsapp' => 'Whatsapp',
])
->columnSpan('full'),
]),

];
}
public function create(): void
{
dd($this->form->getState());
}


public function render()
{
return view('livewire.contact-form');
}
}
<?php

namespace App\Livewire;

...

class ContactForm extends Component implements HasForms
{
use InteractsWithForms;

public $email;
public $first_name;
public $last_name;
public $phone;
public $message;
public $comm_method;

protected function getFormSchema(): array
{
return [
Grid::make(2)
->schema([
TextInput::make('first_name')->required(),
TextInput::make('last_name')->required(),
TextInput::make('email')->required(),
TextInput::make('phone'),
Textarea::make('message')
->rows(5)
->cols(20)
->columnSpan('full')
->maxLength(4000),
Radio::make('comm_method')
->label("Preferred Communication Method")
->options([
'email' => 'Email',
'messenger' => 'Messenger',
'viber' => 'Viber',
'whatsapp' => 'Whatsapp',
])
->columnSpan('full'),
]),

];
}
public function create(): void
{
dd($this->form->getState());
}


public function render()
{
return view('livewire.contact-form');
}
}
Solution:
You have a create method so just create new record there as you would without filament
Jump to solution
2 Replies
Solution
krekas
krekas2y ago
You have a create method so just create new record there as you would without filament
.orelyus
.orelyusOP2y ago
Alright thanks! My tiny brain overlooked it

Did you find this page helpful?