Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

carrying over old POST values with new POST values

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
US
I have a form with 8-10 different fields that people can search a database with. The results are displayed in tabular form upon submission of a search. You then have the ability to sort that query by clicking on the column header you would like to sort by. I do this now by storing the query as a session variable.

HOWEVER, the problem with my approach is that the values the user has entered or selected in the search form disappear upon sorting the result set. The "sort" variable is sent via GET, so when they click to sort by Client Name, for instance, they are taken to "jobs.php?sort=client". By storing the user's search query as a session variable, I'm able to take the query and just tack on the sorting at the end of the query. However, I really want to be able to keep the user's selections in the form selected.

Is there any way I can turn the sortable column headers into forms that submit via POST and still retain the old values of the form? It would be easy to insert them into hidden fields, except for the fact that many of the POST variables that need to be saved are actually arrays that correlate with multiple-select dropdown boxes.

Sorry if any of this is unclear... I can explain further if needed. I just wanted to see if anyone had any ideas on how to go about this?
 
Can you not put them in the session store as well as he query ?
 
The form values have to be generated by your PHP code - it's up to you to generate the required HTML so that the previously selected/filled in values are represented.

When you generate the form output check for the posted values and construct the form field reflecting the correct state. I.e., for a <select> element print selected in the appropriate <option> tag, analogous checked for checkboxes, and value="..." for text boxes etc. I think you get the jest of this.
 
DRJ478 - I can populate the fields correctly when that form has been submitted, BUT when the user refreshes the page using a separate GET query, those POST values don't carry over.

ingresman - I've tried storing the arrays in the session store, but with lackluster results.
 
Set the posted values into a session variable. If the page is accessed via GET, there won't be the posted values, but they will be still accessible in $_SESSION.
With the session values set to the $_SESSION array are available throughout all scripts that use session_start();

Just don't forget to wipe out the content of the vars stored in the session when a new search is executed.
 
I would use sessions(), but there is actually an option:
You can use image submit buttons!

I would however go for session and regular hyperlinks, but read up here if you are interested in it:

there are down-sides, as with everything.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top