getState without Validation
Hello,
is there away to
get form->getState()
without triggering validation?22 Replies
$this->form->getRawState()
tried it but returns empty array
Can you share the code please?
<div>
<x-filament::header
heading="{{ $title }}"
subheading="Plan your campaigns here."
/>
<form wire:submit.prevent="submit">
{{ $this->form }}
<x-filament::button class="mt-4" type="submit">
{{ __('Create EmailCampaign') }}
</x-filament::button>
</form>
</div>
what about the php class?
public function submit()
{
$state = $this->form->getRawState();
dd($state);
}
while $this->form->getState()
works perfectlydid you follow these steps?
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#adding-the-form
mount, statepath..?
yes
if something is wrong
form->getState()
won't workmaybe... did you try
$this->data
?What's your form definition?
class Register extends Component implements HasForms
{
use InteractsWithForms;
use PerformsRedirects;
public $name = '';
public $email = '';
public $password = '';
public $company = '';
public $terms = false;
public function register(): void
{
$user = (new CreateNewUser())->create($this->form->getState());
Auth()->login($user);
$this->redirect($this->redirectTo ?? Filament::getUrl());
}
public function render(): View
{
return view('livewire.auth.register');
}
protected function getFormSchema(): array
{
return [
TextInput::make('name')->autofocus()->required(),
TextInput::make('email')->email()->required()->unique('audience', 'email'),
TextInput::make('company')->required(),
TextInput::make('password')->required()->password(),
Checkbox::make('terms')->required(
fn () => Jetstream::hasTermsAndPrivacyPolicyFeature()
)->hidden(
fn () => ! Jetstream::hasTermsAndPrivacyPolicyFeature()
)->label(
fn () => new HtmlString(
'I agree to the <a class="underline" href="/terms" target="_blank">terms of service</a> and <a href="/privacy" target="_blank">privacy policy</a>.'
)
),
];
}
}
?
wire:submit.prevent="submit"
where is the submit method?still empty
wire:submit.prevent="submit"
where is the submit method?
public function submit()
{
$state = $this->form->getRawState();
dd($state);
}
try to remove properties and add this
you saved the day!!! Thanks!!
I think if you don't have statepath, you should do
$this->name
, $this->email
..for any default values
public function mount(): void
{
$this->lastSaved = now();
// other values
$this->form->fill();
}
@Leandro Ferreira yes, for short schemas $this->name
method gonna work. but for longer schemas it's easier and better to use public ?array $data = [];
protected function getFormStatePath(): string
{
return 'data';
}
@Dennis Koch I think documentation should include this caseI mean that
$this->form->getRawState()
will return []
while $this->getState()
works fine which might be confusing without digging deeperI think the Filament documentation is a good way to understand how Filament works. And if you're up for some more advanced stuff, diving into the source code could be pretty enlightening..