[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Accessing QUERY during a form POST
From: |
Stephen F. Booth |
Subject: |
RE: Accessing QUERY during a form POST |
Date: |
Thu, 8 Mar 2001 18:53:38 -0600 |
OK, now I understand what you're trying to do; I wasn't clear before. What
your program does is a little nonstandard as far as CGI usage is concerned;
the CGI spec doesn't really address the way you're doing things one way or
another. So anyway, what I'm saying is that I haven't seen anyone do that
before. But anyway, to answer your question, with the way cgicc is
currently written you cannot access the _parsed_ query string and post data
together (using the supplied classes). The data that is parsed is only that
data specified by the REQUEST_METHOD environment variable. However, you
have a few options that might make things easier than instantiating two
Cgicc objects (this is assuming the library stays as-is). The best option I
have come up with is to do the following: you could change the constructor
of Cgicc to call parseFormInput() with both sets of data (the GET and POST
data), ie replace
if(stringsAreEqual(getEnvironment().getRequestMethod(), "post"))
parseFormInput(getEnvironment().getPostData());
else
parseFormInput(getEnvironment().getQueryString());
with
parseFormInput(getEnvironment().getPostData());
parseFormInput(getEnvironment().getQueryString());
which should parse everything for you. Sorry I didn't know what you were
getting at earlier.
-Stephen
> I'm missing something, or maybe I did not explain my problem well enough.
>
> My CGI app is responsible for a host of operations, therefore I read the
> Query string every single request, whether it is a FORM POST, or a GET
> request, I must be able to read the Query string. Here'a sample:
>
> http://localhost/mycgi.cgi?op=add&obj=rolodex
>
> This would display the add screen for the Rolodex portion of my program.
> I read the op (Operation) and then the obj (Object) that the Operation
> is to be performed on. Now, Once I enter the information into the form
> that was presented (oh, by the way, the form ACTION is
> http://localhost/mycgi.cgi?op=update&obj=rolodex), I then hit the submit
> button.
>
> Now, there is POST information like:
>
> name=George+Smith&phone=555+555+1234&zip=22321
>
> but I must be able to read what I am sopose to do with this information,
> and it's on the QUERY string:
>
> http://localhost/mycgi.cgi?op=update&obj=rolodex
>
> My program looks something like (pseduo code)
>
> main()
> if (queryString("op")=="add" AND queryString("obj")=="rolodex")
> showRolodexAddForm()
> elseif (queryString("op"=="add" AND queryString("obj")=="note")
> showNoteAddForm()
> elseif(queryString("op"=="update" AND queryString("obj")=="rolodex")
> readPOSTDataAndInsertRolodexEntry()
> elseif(queryString("op"=="update" AND queryString("obj")=="note")
> readPOSTDataAndInsertNoteEntry()
> else
> displayHomePage()
>
> ----------
>
> So on each request I must be able to read the QUERY string as well as
> the POST data, no matter
> the REQUEST_METHOD. The only way I have found to do this so far is:
>
> setenv("REQUEST_METHOD","GET");
> Cgicc queryCGI;
> setenv("REQUEST_METHOD","POST");
> Cgicc postCGI;
>
> form_iterator op_ele = queryCGI.getElement("op");
> form_iterator obj_ele = queryCGI.getElement("obj");
>
> string op = op_ele->getValue();
> string obj = obj_ele->getValue();
>
> ...etc...
>
> form_iterator name = postCGI.getElement("name");
> execSql("INSERT INTO Rolodex (name) VALUES ('" + name->getValue() + "')");
>
> ...etc...
>
> Is this the only way to do it, or am I missing something?