[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Accessing QUERY during a form POST
From: |
Jeremy Cowgar |
Subject: |
Re: Accessing QUERY during a form POST |
Date: |
Thu, 08 Mar 2001 10:02:53 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux 2.4.0 i686; en-US; m18) Gecko/20010131 Netscape6/6.01 |
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?
Jeremy - address@hidden
Stephen F. Booth wrote:
Cgicc will parse the strings for you. You need to use the accessor methods
on the Cgicc class. IE,
form_iterator name = cgi.getElement("name");
Look at the sample CGIs or the info files for more info. There is a brief
tutorial that I think will help you out.
<excerpt>
Each element of data entered by the user is parsed into a FormEntry. A
FormEntry contains methods for accessing data as strings, integers, and
doubles. In the hypothetical form mentioned above, a user would enter their
name, age, and sex. Regardless of the type of value, the data is accessed
via FormEntry2. You obtain FormEntry objects via Cgicc's getElement methods,
all of which return typedefs of standard-library iterators:
form_iterator name = cgi.getElement("name");
If the item is not found, the iterator will refer to an invalid element, and
should not be dereferenced using operator* or operator->. Cgicc provides
methods for determining whether an iterator refers to a valid element:
if(name != cgi.getElements().end()) {
// iterator refers to a valid element
}
I have already tried both getPostData() and getQueryString() but
that returns the unparsed string. How do I go about parsing that
information once I have it in a string? I was hoping that the
Cgicc class could do that for me.