Forum OpenACS Q&A: Passing parameters between pages
I know of 2 ways to pass parameters between pages at the moment: - using ad_page_contract to get the variables after a form post - using additional URL information such as blah?number=2 Im not too keen on the 2nd option unless its just simple information as I dont want to send sensitive information in the URL line. Other than this method, is it possible to pass a variable to the next page without using a form? The variable im trying to pass is an ID which is open for the user's session so I want to access this on every page. Any ideas? Thanks, Ayman
Do this using:
ad_set_client_property mymodule idname value
Then you could do something like alter the request processor such that it will put your id into the ad_conn array.
Then you would read it like:
set my_id [ad_conn idname]
Alternatively you could just read from the cookie every time.
set my_id [ad_get_client_property mymodule idname]
Hope this helps
If it is something that identifies the user, you can store it in a cookie and query that on page loads. OpenACS does that for user_id. The other option is to store it in the database, and query based on user_id.
Other than that I can't think of any way to pass information between pages. That is the way HTTP is designed. There are two operation that are mostly used GET and POST. GET passes the parameters in the URL and is used to retrieve information. POST uses form variables and is used to trigger a change, for example, inserting, deleting or updating a row in the database.
ad_set_client_property writes to the sec_session_properties table, mapped against someones session_id, which I think in your case is perfect.
<form method="POST" action="foo.tcl?var1=blah">
<input type=text name=var2>
will deliver values for both var1 and var2 to the server.
If you examine the HTML headers for your HTTP traffic (I highly recommend that if you want to learn how HTTP requests work - one method for Windows clients is the PC Magazine utility Cookie Cop 2, which has an HTTP viewer), you'll see the embedded variable info from a POST.