Skip to content Skip to sidebar Skip to footer

How To Keep Post Method's Input Values With Post/redirect/get?

Using the post/redirect/get pattern, you can prevent duplicate form submission. For example, you can prevent a visitor of your online shopping website from ordering the same item t

Solution 1:

You need to transport those values via GET. There are two options to do that:

  1. sessions
  2. URL query parameters

If you simply save the data in the session, you can read it from there and re-populate the form. If you put it into the URL, you can read it from there; but obviously the URL will contain a lot of data then.

Reading it from a session the data will not be unique to the specific page/redirect, but anyway you open that page again within the same session will show the same data. Passing the data via the URL will make it unique to the specific request.

As a middle ground, you can save the data in the session tied to a specific random id, redirect with this id in the URL (e.g. example.com/foo.php?i=12345), the re-populate the data from the session with the specific id.

Solution 2:

I does not tested the below code, but I believe it pretty helpful to you.

It only works, if you are working on Laravel framework.

Please try this..

  return redirect('/Your-page-url')
            ->withInput();  

Solution 3:

It seems you're looking for session storage

Post a Comment for "How To Keep Post Method's Input Values With Post/redirect/get?"