Multiple forms page

I am using multiple forms in filaments and when I initialise $this->form->fill() in mount. Property [$form] not found on component: [v1.admin.messaging.send-s-m-s] , this doesn't happen in single form. And when I comment out $this->form-fill()`, I get this
Typed property App\Livewire\V1\Admin\Messaging\SendSMS::$data must not be accessed before initialization
Typed property App\Livewire\V1\Admin\Messaging\SendSMS::$data must not be accessed before initialization
. How do I resolve it??
No description
No description
Solution:
public ?array $data = [];
Jump to solution
15 Replies
Solution
awcodes
awcodes5mo ago
public ?array $data = [];
awcodes
awcodes5mo ago
It needs to be initially set in this case.
KingNii
KingNii5mo ago
@awcodes Thank you!!! @awcodes $this->form->fill() has now thrown an error Property [$form] not found on component: [v1.admin.messaging.send-s-m-s]
awcodes
awcodes5mo ago
You’re also missing the HasActions interface and the InteractsWithActions trait
KingNii
KingNii5mo ago
This happens when comment out the $this->form->fill()
No description
awcodes
awcodes5mo ago
Would need to see more code to help more. Also the blade view.
KingNii
KingNii5mo ago
@awcodes
No description
awcodes
awcodes5mo ago
You have multiple forms so you need to match your statePath for each one, you’ll need two different arrays to store the data, and in mount it would be $this->singleForm->fill(), etc. And in the view {{ $this->singleForm }} The error is correct there is no $form because you have redefined it to the two names on your getForms method.
KingNii
KingNii5mo ago
@awcodes this is the results after making the change.
No description
KingNii
KingNii5mo ago
<div id="adminSMS">
<div class="w-full min-h-screen p-2 space-y-5 bg-gray-300 adminSMS">
<div class=""></div>
<div class="w-full px-5 py-4 mx-auto rounded-lg shadow-lg md:max-w-md bg-white/50">
<form action="">
{{ $this->singleForm }}
<div class="mt-4">
<button class="w-full px-4 py-2 font-bold text-white bg-green-600 rounded hover:bg-green-700">
Send SMS
</button>
</div>
</form>
</div>
<div class="w-full px-5 py-4 mx-auto space-y-4 rounded-lg shadow-lg md:max-w-lg bg-white/50">
<form action="">
{{ $this->massSMSForm }}
<div class="mt-4">
<button class="w-full px-4 py-2 font-bold text-white bg-green-600 rounded hover:bg-green-700">
Send SMS
</button>
</div>
</form>
</div>
</div>
</div>

<div id="adminSMS">
<div class="w-full min-h-screen p-2 space-y-5 bg-gray-300 adminSMS">
<div class=""></div>
<div class="w-full px-5 py-4 mx-auto rounded-lg shadow-lg md:max-w-md bg-white/50">
<form action="">
{{ $this->singleForm }}
<div class="mt-4">
<button class="w-full px-4 py-2 font-bold text-white bg-green-600 rounded hover:bg-green-700">
Send SMS
</button>
</div>
</form>
</div>
<div class="w-full px-5 py-4 mx-auto space-y-4 rounded-lg shadow-lg md:max-w-lg bg-white/50">
<form action="">
{{ $this->massSMSForm }}
<div class="mt-4">
<button class="w-full px-4 py-2 font-bold text-white bg-green-600 rounded hover:bg-green-700">
Send SMS
</button>
</div>
</form>
</div>
</div>
</div>

awcodes
awcodes5mo ago
That’s not correct $this->singleForm->fill() ‘form’ doesn’t exist anymore. It’s now ‘singleForm’ and ‘massSMSForm’
KingNii
KingNii5mo ago
@awcodes I am really really GRATEFUL
awcodes
awcodes5mo ago
No worries.