Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ponnydalen's avatar

Form Confirmation Page

Hello. I have made a booking form and I have a question regarding the redirection after the form is submitted. What I want : Simply redirect after submit to another route with a new view, and show a "Confirmation page with the form data". Something like this -

Thank you {$firstname, $lastname}. Your booking has been successfully submitted. We have sent you an email to {$email}, etc..

So far I've tried this

   return view('client/pages/confirmation', compact('booking', $booking));

And it works and shows the data correctly. The issue is if I reload the page, the form is getting sent one more time :/

I have also tried this:

 return redirect()->route('confirmation',['id'=>$booking]); 

//Using this route
Route::get('/bestilling/bekreftelse/{id}', 'BookingController@confirmation')->name('confirmation');

//Using this function
public function confirmation($id) {

    $booking = Booking::whereId($id)->first();

    return view('client/pages/confirmation', compact('booking', $booking));
}

And now i'ts just to change the url ID and you have access to another guy's booking..

Someone knows how this can be done the safest way? With sessions?

0 likes
6 replies
Snapey's avatar
Snapey
Best Answer
Level 122

Never return a view at the end of a post request

ALWAYS return a redirect

return the user to a thankyou page, with a reference in the URL to their order. Retrieve their order from the database and say thanks.

Your second approach is correct, and to prevent tampering, use a signed URL

https://laravel.com/docs/7.x/urls#signed-urls

or use a hard to guess, non-sequential reference such as a UUID

ponnydalen's avatar

Thanks for reply. I tried using this signed URL but I think I don't fully understand where to put what now.. Little bit confused. I ended up getting this url BUT it appears in my view ( like in the document)

http://quickpark.no/kvittering?expires=1598892082&signature=63785ce10cde8726e1d984878e00a38d43275b4a947edaff62a72035b0c394fa&id&130

I return this from my controller after form submit and save to db :

 return redirect()->route(
        'confirmation', ['id' => $booking]
    );

Then in my routes:

Route::get('/bestilling/{id}', function ($id, Request $request) {

    return URL::temporarySignedRoute('bestilling', now()->addMinutes(5), ['id', $id]);
    
})->name('confirmation');

Route::get('/kvittering', 'BookingController@confirmation')->name('bestilling');

But I never get to my controller(confirmatio method) where I should return the view with data

  public function confirmation($id) {

    return view('client/pages/confirmation', ['booking' => Booking::findOrFail($id)]);
}

What am I doing wrong?

Snapey's avatar

create the signed route in the controller redirect statement

ponnydalen's avatar

I did this in my redirect

$url = URL::temporarySignedRoute('confirmation', now()->addMinutes(5), ['id'=>$booking]);
    return Redirect::to($url);

Routes :

Route::get('/kvittering/{id}', 'BookingController@confirmation')->name('confirmation');

Controller that return view:

 public function confirmation($id) {

    return view('client/pages/confirmation', ['booking' => Booking::findOrFail($id)]);
}

And it works:) I dont know if it's the proper way, but it does what I want so ..thank you Snapey.

ponnydalen's avatar

My controller return view method is ofc like this instead :

	public function confirmation(Request $request, $id) {

    if (! $request->hasValidSignature()) {
        abort(401);
    }

    return view('client/pages/confirmation', ['booking' => Booking::findOrFail($id)]);
}

I forgot to update.

Snapey's avatar

good. Please mark it as answered if you are happy.

Please or to participate in this conversation.