Redirect on save

Published 4 years ago by christopher

Hey,

If i create or update something i want to give the user the possibility to "save" or "save & back".

In my controller i have currently this:

return Redirect::to('/profile')->withInput()->with('success', 'updated.')

How can i add a secound return IF the user clicks "save & back" ?

return Redirect::back()->withInput()->with('success', 'updated.')
Best Answer (As Selected By christopher)
kreitje

Name the submit buttons differently.

<input type="submit" name="save" value="Save" />
<input type="submit" name="save_and_go_back" value="Save & Back" />

Then in your code

if ( Input::has('save_and_go_back') ) {
// redirect back
} else {
// redirect to the profile
}
kreitje

Name the submit buttons differently.

<input type="submit" name="save" value="Save" />
<input type="submit" name="save_and_go_back" value="Save & Back" />

Then in your code

if ( Input::has('save_and_go_back') ) {
// redirect back
} else {
// redirect to the profile
}
christopher

Ok works thanks :)

One other question: If i do

Redirect::back()

i`m still on the same site ( create form ) why do i not get redirected to the previous page?

kreitje

Redirected to the page prior to the create page, or redirect back to the create page?

christopher

I want that a user can a) Redirected to the page prior b) Redirect back to the create page

kreitje

Ok yeah, Redirect::back() won't work. When you submit the form it checks where it is coming from.

What you could do is add a hidden field where it needs to be redirected back to. Then check if that input was submitted and redirect where it says.

Please sign in or create an account to participate in this conversation.