Jump to content

Remembering form data when using pagination


perky416

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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 :).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.