perky416 Posted April 2, 2011 Share Posted April 2, 2011 Hi Eveyone, Is it possible in php to remember form data when scrolling through pages set up using pagination? Usually i use value="<?php echo $_POST['field_name']; ?>" to remember the form data if the submit button has been pressed. Im trying to get it so that if i fill out a field on page 1, then i go to page 2, if i come back top page 1 the field is still populated. Scrolling through the pages nothing is actually posted so the fields are becoming empty when returning to them. All help is greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/ Share on other sites More sharing options...
SamT_ Posted April 2, 2011 Share Posted April 2, 2011 PHP does not store variables between page loads; you need to pass it all via a GET request or cookies. I don't consider cookies reliable for such things (say they have two windows open doing the same thing). My suggestion is to create some sort of processing function to generate the pagination link which will add all the appropriate vars to next page link. Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1195978 Share on other sites More sharing options...
nethnet Posted April 2, 2011 Share Posted April 2, 2011 You could append it to the URL and grab it using $_GET instead of $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1195979 Share on other sites More sharing options...
Genesis730 Posted April 2, 2011 Share Posted April 2, 2011 $_SESSION variables? Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1195981 Share on other sites More sharing options...
perky416 Posted April 2, 2011 Author Share Posted April 2, 2011 I did consider passing it through the URL and then using GET however the user has the option to edit up to 100 fields at a time, then if they go over a few pages before submitting the form that could be 300 pieces of data in the URL which i thought was a bad idea. I also tried using $_SESSION, however i haven't used them that much before so i may have got it wrong. I simply tried using value="$_SESSION['form_name']'" in the form field. Would i have to do something else? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1195988 Share on other sites More sharing options...
nethnet Posted April 2, 2011 Share Posted April 2, 2011 Well, first of all, sessions will only store between pages if you have session_start() called at the beginning of every page. So if you intend on using sessions, make sure you start them on every page (the call function needs to be placed before ANY browser output). Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1195994 Share on other sites More sharing options...
RussellReal Posted April 2, 2011 Share Posted April 2, 2011 sessions are the best possible solution.. how a session works is easy to understand, and you'll maybe be able to use them better. #1 when you call session_start() it will look thru the REQUEST variables (Cookie, Post, Get) looking for PHPSESSID. When PHP finds this variable it will access it find the string contained within, and open up a file.. if there IS NO PHPSESSID then it will create that variable (which is why it needs to be called before any output.. setting a COOKIE requires no output to be sent) #2 once the file is located which contains your user's SESSION.. it is opened and loaded into a regular-not-so-special variable called $_SESSION #3 then you will use $_SESSION just like you'd use any other array.. except, anything you put into $_SEsSIOn or take away from $_SESSION will be recorded inside of that user's session file . Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1195996 Share on other sites More sharing options...
perky416 Posted April 2, 2011 Author Share Posted April 2, 2011 Hi guys, session_start() is used on every one of my pages as I use it to identify if a user is logged in. Please tell me if im wrong but from what i have read, without using the GET or cookies (in case the user has cookies turned off), to store the form data in a session wouldn't it have to be posted? $_SESSION['price'] = $_POST['price']; As iv used pagination, effectively everything is the same page, however it displays a different part of the database depending on which link is pressed. Example: if the user clicks <a href'page.php?start=10'>Page 2</a>, they will still be on page.php, however the info shown on the page will only be displayed from the 11th result in the database onwards. Quote Link to comment https://forums.phpfreaks.com/topic/232514-remembering-form-data-when-using-pagination/#findComment-1196061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.