Forum OpenACS Q&A: Re: Using GET and POST variables

Collapse
Posted by Don Baccus on
I just ran into a similar problem myself, and there's an easier way.

First, to just get the query variables for either GET or POST you can do this:

ad_page_contract -form [ns_parsequery [ns_conn query]] ...

And define your variables in traditional ad_page_contract style.

This works for the case I'm working on, because the POST data is actually being sent as content rather than a form variable, and I get the data with ns_conn content (the content actually shows up in the global _ns_form, but as the *key*, with the value blank, i.e. AOLserver is being confused).

However, using ns_set merge, you should be able to get both the querystring vars and the form vars like this:

ad_page_contract -form [ns_set merge [ns_getform] [ns_parsequery [ns_conn query]]] {

Here's the documentation on ns_set merge:

http://aolserver.com/man/4.0/tcl/ns_set.html

If you call this script with GET, _ns_form will already have your query vars in it, and ns_set merge won't touch them in _ns_form.

On the other hand, call it with POST, and the vars defined in the query string will be merged with the form vars already set in _ns_form, and off you go.

I haven't tried the merge case (since I don't need it), but it should work ...