So I am creating an application that manages users with the CRUD operations using Route::resource.
I have the following pages:
index page (get) - which shows the list of users. Within each user row there are two buttons that links to the edit() method and show() method.
edit page (get) - which shows the form with pre loaded saved data so that the can edit from there.
show page (get) - which displays the users's information
update (put) - which saves all the fields provided by the user to the database.
After when the I update, I want to redirect to the index page (which shows the list of users)
if($user->save()){
Session::flash('usersaved', 'The user: '.Input::get('user_name'). ' was saved');
return Redirect::route('admin.users.index');
}
The redirect back to the index works correctly with the message BUT, right after I press the link that goes the to show() method (only on the edited client) and then press the back button on the browser (Google Chrome), it takes me to the edit() method not the index() method (list of users)!
Whats going on here?
Many thanks!
If you have no problem with other browsers, I guess this is caused by Chrome not adding a history entry after the redirect (Chrome developers do not consider it to be a bug while the rest of the world seems to).
Related
I have a web page that loads all the data from a mysql database called datalist.php
From this page I can edit record by record with a button that redirects you to an editdata.php page adapted to the fid of the record.
Once edited as they want to see the changes, I don't redirect them to the main one letting them see the changes and simply clicking back or with a button they return to the datalist.php without any problem.
The button is this
echo "<p id='parrafo'><a style='padding:1px 20px'class='button rounded-0 primary-bg text-white w-0 btn_1 boxed-btn' href='javascript:history.back() '><--</a></p>";
PROBLEM
I added a search engine where the displayed data can be filtered.
When they use the search engine from datalist.php, I direct them to a page called search engine.php where, through a post method, I store what they are looking for in a variable and the data that users want appears.
But when they edit a filtered record, it is edited without problems, but when they go back, they return to the search engine.php and the message appears:
"Confirm form resubmission In order to display correctly, this web page needs the data you entered earlier. You can submit that data again, but that will cause the page to repeat all previous actions. Press Reload to submit the data and display the page.
Hit the page refresh button to resubmit the data needed to load the page."
Of course, if they update, they come back when the filtered data comes out.
Isn't there any way to store the variable used in the search so that when I go back I don't get this error or any solution??
simple! when user will submit form for that variable instead of making post request
option1: just use get request __url__?variable=... but this will not remember the variable when you go back
option2: store the variable in the cookie and just go to next page (eg. window.location.href = '...';). and in next page access the cookie from php.
If you are wanting to show the form to the user as a confirmation, but without the possibility of another post, then remove the form element and the button. Display all other boxes as they are (with the values populated from the POST array).
And display another message telling them that it has been successful.
You are using PHP, you can achieve this easily with it. If you are unsure, then post a short version of your code in a separate question.
I am having a small issue with my Laravel 5.2 application. The problem is with a page made to adjust database entries.
When data has been adjusted and a button is pressed to update the database, it works great. Problem is, I would like to redirect back() to the previous page, but this page has been set up through data from other pages.
So when I redirect back, it error's and says that certain parameters are not defined. Is there a option, that I can implement a very static redirect to the previous page and all the data that has been loaded in the page?
Like the go back function that web browsers have?
Solution
I added the following code in the Controller function where the page is made to adjust the database entry:
Session::flash('url',Request::server('HTTP_REFERER'));
And as a redirect I have this:
return Redirect::to(Session::get('url'));
Maybe I'm missing something but I can't figure out how to do this.
I have a index view that lists all the records from my tiers table. The page has a "Create New Tier" button that displays a form. The user enters the data for the new tier and hits the submit button. In my TierController I have the following:
public function store()
{
//
$data = Input::all();
$tier = new Tier();
$tier->name=$data['name'];
$tier->price = $data['price'];
$tier->save();
return Redirect::back()->with('message',"Tier created successfully.");
}
This takes me back to the empty create form and displays the message but the user has to press the back button to return to the index view which doesn't show the new data until I hit refresh. I would like to have the system automatically return to the index view after the submit button is clicked with the refreshed data.
I know that I can do a Redirect::to('tiers.index')->with('message','Tier created successfully') but the problem I have with that is then the browser history looks like
tier.index -> tier.create -> tier.index
This then is very confusing for the user when they do hit the back button as the create view shows up and freaks them out.
Is there a way to do a Redirect::back (or something) that would not leave the tier.create view in the history and also refresh the index data?
Thanks
I don't think you can manipulate the user's browsing history without resorting to Javascript or something. Certainly not with Laravel alone. So, don't. You're overthinking this. Why do you care so much about what's in the browser's history? And why would you want to manipulate it so that it doesn't reflect the pages the user actually went through? It sort of defeats the purpose of having a history...
If your app's navigation is sufficiently intuitive and familiar, the user won't feel the need to use the native browser's back / forward buttons. Don't assume your users will make the most basic browsing mistakes unless you have data to back that up.
Having said that, conventions don't give you much choice in this matter: generally you either lead the user back to the index -- i.e. Redirect::route('tiers.index') -- or to the newly created item -- i.e. Redirect::route('tiers.show', $tier->id). Both are perfectly acceptable and surely within the user's expected outcome.
If tiers are something the user can only add within certain limits (one per user, one per category, once a day, etc), then I'd attempt to redirect him away from the create page, preventing him from filling out a fresh form which won't ever pass validation. Otherwise, chose one of the pages above and move on to your next development challenge.
I am a newbie to programming. I have a PHP website which works as follows
Index Page - Search Results - Show a Product
The site user enters search critera on Index Page and the page is POSTed to Search Results page. From there, the site user clicks on a Product href that takes him to the Product Details. This is working fine till here.
The problem occurs when the user click the browser BACK button. The Search Result page comes up totally crashed and the user has to press F5/Browser Refresh to re-submit it. Any idea/technqiue that I can use to avoid this crash?
When a browser goes back to a page that comes from POSTing some data, the browser often times needs to re-POST the data in order to get the same page back. Since that can sometimes be bad (e.g. re-POSTing an order form), many browsers require the user to force a refresh with a warning.
You can generally use a GET instead of a POST form to avoid this.
An idea would be using GET for the method of your search form instead of POST (that apparently you are using). That way, even if going back in browser history, your server could re-supply its search results.
You would need the following:
change method="post" to method="get" in your search form
change every $_POST relating to the search form data to $_GET in your search form processing php file.
Of course, it could not work for your specific usecase. That's just an idea.
Lets say I have a Page with a List (list.php).
I click on a row on that list to Edit that record. I go to a edit.php Page.
I have 3 buttons on that edit.php page. Save, Apply, Cancel
Save button - Saves the Record and returns to the (list.php) Page
Apply button - Saves Record but stays on the same page (edit.php)
Cancel button - No save, just return to the (list.php) Page
But now image if I can access for edit that item on a different page. How do I return to that calling page?
Do I add a parameter(code) to the URL? something like a Page Origination Code?
Do I save the previous page URL in a session? (bad, they can right click open another page and that would be saved to session url)
Am just curious to how others return to a previous page after a SAVE.
you can the server variable $_SERVER['HTTP_referrer'].
They are other ways also you can store in session the current page and use is processing page.
Adding a parameter to the URL is the only reliable though quote ugly way.
That's why such an in-place editions nowadays often being implemented using AJAX, and this very site is a perfect example.
However, there are different cases.
Login page is imperfect example for example, as you always have a form instead of just a link, and thus you can always store the current page in a hidden form field.
Another approach is possible if you are using some sort of front controller, and all requests actually being directed to the single index.php file which runs appropriate script based on the URI.
in this latter case you will need no more than mere a redirect to the current page.