DOCUMENTATION

ft_api_load_field

This invaluable little function is a wrapper for ft_load_field, used in the core script. It's used for storing and overwriting the contents of a single form field in sessions based on a sequence of priorities.

It assumes that a variable name can be found in GET, POST or SESSIONS (or all three). What this function does is return the value stored in the most important variable (GET first, POST second, SESSIONS third), and update sessions at the same time. This is extremely helpful in situations where you don't want to keep having to submit the same information from page to page. The third parameter is included as a way to set a default value.

It takes three parameters:

  1. the field name
  2. the session key used to store the value
  3. the default value

One common place for this is to store the current page in memory for a paginated list of data:

This does the following: the first time the page is loaded, it uses the third parameter - the default value "1" (page 1). If the query string contains a page=X value or if the page has received a field called "page", it overwrites the value in sessions and stores the appropriate value in $page. The nice thing is that you don't need to keep sending the "page" value to the webpage. It will always remember the last value. This can save you a lot of fuss and bother!

A technical note

The function information is actually stored here: $_SESSION["ft"][session key] - e.g. in the previous example, it would be stored: $_SESSION["ft"]["session_page"]. So in case you need to empty it, you'll need to directly modify that value in sessions.