F
Filament16mo ago
青木

How do I submit a form automatically?

I'm implementing a function to bind tenants. 1. I want to execute the bind function directly when the url contains /bind?code=abc 2. render a page for the user to enter the code when it doesn't exist. What should I do? I tried to do this, but I don't know how the form should be submitted automatically.
TextInput::make('code')
->label('Code')
->required()
->helperText(
'Please enter the code provided by your company. If you do not have a code, contact your company administrator.'
)
->default(function (Set $set, Request $request) {
if ($request->has('code')) {
return $request->get('code');
}
return null;
}),
TextInput::make('code')
->label('Code')
->required()
->helperText(
'Please enter the code provided by your company. If you do not have a code, contact your company administrator.'
)
->default(function (Set $set, Request $request) {
if ($request->has('code')) {
return $request->get('code');
}
return null;
}),
1 Reply
青木
青木OP16mo ago
I tried this and it auto-submits the form, but I'm not sure if it's elegant.
<x-filament-panels::page.simple>
<x-filament-panels::form wire:submit="register">
{{ $this->form }}

<x-filament-panels::form.actions
:actions="$this->getCachedFormActions()"
:full-width="$this->hasFullWidthFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page.simple>

<script>
// Alpine on mounted
document.addEventListener('alpine:initialized', () => {
window.setTimeout(function() {
// check if we have a code in the url
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
@this.register();
}
}, 300);
})
</script>
<x-filament-panels::page.simple>
<x-filament-panels::form wire:submit="register">
{{ $this->form }}

<x-filament-panels::form.actions
:actions="$this->getCachedFormActions()"
:full-width="$this->hasFullWidthFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page.simple>

<script>
// Alpine on mounted
document.addEventListener('alpine:initialized', () => {
window.setTimeout(function() {
// check if we have a code in the url
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
@this.register();
}
}, 300);
})
</script>
Want results from more Discord servers?
Add your server