F
Filamentβ€’13mo ago
Husky110

Posting data from one page to another with a form

Hi - What I wanna do is post data from one custom page to another via POST-Request. Right now I face three issues: 1.) How does the Target-Page has to look like so it's route is only accessable through a post-request? I guess I have to modify the getRoutes()-function to look like this:
return function () {
Route::post(self::$slug, self::class)
->middleware(self::getMiddlewares())
->name($slug);
};
return function () {
Route::post(self::$slug, self::class)
->middleware(self::getMiddlewares())
->name($slug);
};
Right? 2.) How do I access said post-data inside the target-page? 3.) How does my submit()-function has to look like? getState and such yes, but is it as simple as return redirect(TargetPage::getUrl(['post-data' => $this->form->getState()])) ? Edit: Just to clarify - I do not want to do something with a model here. Basically I'm building a multi-step-process with some pages where one step's data is dependent on the last step's values (which is why I don't use Steps or Wizards).
23 Replies
Dan Harrin
Dan Harrinβ€’13mo ago
i dont understand, what is the point? this is what Livewire is for, no?
Husky110
Husky110β€’13mo ago
New to Livewire. Right now I don't need fancy behaviour, but more like classic one. See my edit. πŸ™‚ All examples I see are with creating or editing some models - but here we're talking classic, stupid data. πŸ™‚ Basically it's a complex search-form where only the last step actually does something with a model.
Dan Harrin
Dan Harrinβ€’13mo ago
posting isnt the right option here you should save the data to the database, and then on the next page retrieve it
Husky110
Husky110β€’13mo ago
I just want to send some data via a Post-Request - no need to involve the database here... πŸ˜•
Dan Harrin
Dan Harrinβ€’13mo ago
that isnt how Livewire works and your users will thank you when they dont lose all their work by refreshing the page at least store it in the session, if you dont want to use the database
Husky110
Husky110β€’13mo ago
Possible - but in this case I want the the good old form action="" something and just send it via post-body. actually it's good if they loose it in this case. πŸ™‚
Dan Harrin
Dan Harrinβ€’13mo ago
okay, well you cant use filament forms then, that isnt how this works. you'll have to build your forms from scratch with blade and use a controller
Husky110
Husky110β€’13mo ago
Ain't there a way to modify the submit-function to return the target page? I'm not trying to piss you off - even if it may look like it. πŸ˜„ Just to clarify. πŸ™‚
Dan Harrin
Dan Harrinβ€’13mo ago
yes you could chanage the submit function on the <form>, but the data would not be sent as it is in the JavaScript state of Livewire, not like a traditional form what you are trying to do is overcomplicating this situation much more than it needs to be, because you think it is simpler to use a normal post request. it really isnt its much simpler to store the data in db/session when the form is submitted and then retrieve it again on the next page
Husky110
Husky110β€’13mo ago
Background - I'm implementing a process where a user can look up batches of articles via a batchnumber. First they select an article (first page), then it retrieves all batches from two tables for said articles and the user selects 1-n of them (second page) and then they get the results presented (third page). I'm stuck between second and third. Involving the database is not an option here, since I wanna reduce load on it and idealy I only want my users to only write in only some specific cases. Just using a Post-Request would be the easiest thing to do here - i recon. If you have a better idea, that does not involve the db or session or other temp-storages I'm all ears.
Dan Harrin
Dan Harrinβ€’13mo ago
redirect with the data in the query string is the other option
Husky110
Husky110β€’13mo ago
That was my first idea aswell. But that would put them into the URL-String which has a de-facto limit of 2000 characters, where I can see situations (multiple, large and complicated batchnumbers) where that could be a problem. Hence the POST-Request... πŸ™‚
Dan Harrin
Dan Harrinβ€’13mo ago
there is no way to render a livewire full-page component from a post request. as far as i know.
Husky110
Husky110β€’13mo ago
Okay - I dug a bit deeper and found out that Livewire is a bit of "bad" in that department (see https://github.com/livewire/livewire/issues/990) so I guess I will have to resort to the query-string. But just for the protocoll: I don't like it.
GitHub
Issues Β· livewire/livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs. - Issues Β· livewire/livewire
Dan Harrin
Dan Harrinβ€’13mo ago
its not bad, and I'm not trying to be rude here, but you're completely missing the point of livewire trying to fight against it is not gonna result well
Husky110
Husky110β€’13mo ago
No offense taken - you've been really helpfull so far! πŸ™‚ And I see some huge benefits of livewire. But itself overwriting Laravels own Redirector (which actually would make it possible again) is just... well... oh I'm not. actually I thought I was missing something! πŸ˜„ Devil is always in the details. πŸ™‚
Dan Harrin
Dan Harrinβ€’13mo ago
ok :)
Husky110
Husky110β€’13mo ago
Livewire itself ain't bad. But the aspect of completely ditching POST-Requests -> I think is πŸ’© . πŸ˜„ Okay - so if anyone reads this you have 3 options: 1.) Use the query-string (and enlargen your URLs with multiple-selects) 2.) Go via Database or Session 3.) Flip the table/jump out the window πŸ˜„ Thanks again Dan. πŸ™‚
toeknee
toekneeβ€’13mo ago
There's not really any need for post requests as Dan said. I get what you are trying to do, and I get why you think your way is simpler. Which in traditional world yeah it is. However, you are using livewire now which will massively simplify you're life and improve the UX but you'll have to fully understand how it works. In your scenario, it sounds like a Filament Forms Wizard is what you are looking for, you enter the id's after state updated, you get the data and pass it into step 2, from step 2 you pass it into step as a custom view or custom livewire component with tables implemeneted.
Husky110
Husky110β€’13mo ago
Post-Requests do you another favor - a small security one in fact. πŸ™‚ But I agree that I don't know the ropes of Livewire and Filament enough. πŸ™‚ The docs on wizards are not really enough for me on this one to fully grasp what you are suggesting here. Can you give me some example-code?
toeknee
toekneeβ€’13mo ago
There’s not really a security issue here if your already viewing the form. Provide your full spec of what you are trying to achieve and I’ll see if I can get some time to write you a basic example
Husky110
Husky110β€’13mo ago
I already managed to do it via Queries, since it's nothing crutial. Thank you for the offer tho! πŸ™‚ To the security-aspect: POST-Requests can sometimes give you a little bit of protection through "security through obscurity". I hear some people gasp on that, since it's widespread knowledge that the principle itself does not really work out. While that in true in general, seeing "security through obscurity" as a tool to enhance something already beeing secured to best of knowledge is a bit like sprinkles on a cake. You stop the script-kiddies from messing inside your URLs. It's not really neccesary, but it looks great. πŸ™‚ And while you are right stating "I already see the form - duh!" - making some Request beeing a POST-Request outside a form can have said effect. πŸ™‚
toeknee
toekneeβ€’13mo ago
I’d disagree agree with that one bud when communicating with the same platform. You can see all post requests and data in the network tab, nothing obscure about it. And the majority of livewire requests are post and get depending on the use.