Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > HTTP & Forms : where are name-value pairs stored?

HTTP & Forms : where are name-value pairs stored?
Thread Tools
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 20, 2001, 05:08 PM
 
Hey guys,

Need to know. When an web FORM is submitted, where are the name-value pairs stored? Apache? Client? or Server?

Are they stored in an array in any of those locations? What is the method or call to that array?

I would like to be able to parse the name-value pairs 'dynamically'.

I read the HTTP specs, but I couldn't find anything. Gonna check out Apache next.

Thanks! Hope you guys know.
"Last time the French asked for more evidence, it rolled through France with a German flag." - David Letterman
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
May 21, 2001, 01:46 AM
 
They're submitted as part of the HTTP request, and therefore it's either Apache or the CGI (or other web-based scripting environment) that parses them. It doesn't really matter which. The parsed name-value pairs are then stored in memory on the server while your script executes.

POST data needs to be parsed. I think PHP does this automatically, and there are several PERL libraries around for doing it...
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status: Offline
Reply With Quote
May 21, 2001, 12:03 PM
 
One of the original (and still one of the best) resources on understanding the fundamentals of CGI can be found at
http://hoohoo.ncsa.uiuc.edu/cgi/

The most direct answer to your question is that form parameters are never stored - they are passed like a hot potato from the client (the browser) to the server (Apache) to the handler (CGI perl script, PHP, servlet, whatever.) If the handler chooses to store the data (perhaps to a database), so be it.

Form variables are passed from the server to the CGI differently depending on the method the form was submitted. If the form is being submitted as a GET, the data gets to the handler in the form of an environmental variable, QUERY_STRING. If the form is being submitted as a POST, the data is piped to STDIN on the handler.

Parsing either is straightforward, but there's no need to do it yourself. If you're writing a perl CGI, use CGI.pm which will do it all for you automatically; if you're writing a Java servlet, just look in the HttpServletRequest object; other environments have similar objects or methods.

Erik
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
May 22, 2001, 01:23 AM
 
the Java Servlet API provides everything you are looking for.
http://java.sun.com/products/servlet/index.html
and I wrote a HOW-TO to get Resin JSP/Servlet engine up and running on OS X.
http://www.jspformacs.com/articles/Resin-HOW-TO.pdf

[This message has been edited by Kristoff (edited 05-22-2001).]
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
May 22, 2001, 05:24 AM
 
Your post doesn't say what language you're writing in. Where the values technically exist is irrelevant, unless you're rewriting Apache or something. All you need to know is how to get at them in your language.
  • In PHP, they're all pushed into variables at the start of the script. So, a field called 'name' would become a variable called $name.
  • In Perl, they're stored in various parts of the $ENV array. Go read a Perl reference to find out how to get them.
  • In Java Servlets, they're part of the Request object. Again, go read a reference.
  • I haven't used JSP, ASP or WebObjects.
So which language are you using?
All words are lies. Including these ones.
     
NeoMac  (op)
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 23, 2001, 09:47 PM
 

I'm using PHP.

Does PHP have anything similar to the $ENV array of Perl? It would be much easier to write a script and pull the name-value pairs from the array, rather than have to hard code the extraction of values into the script for each specific web form I use.
"Last time the French asked for more evidence, it rolled through France with a German flag." - David Letterman
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
May 24, 2001, 01:23 PM
 
Originally posted by NeoMac:
I'm using PHP.

Does PHP have anything similar to the $ENV array of Perl? It would be much easier to write a script and pull the name-value pairs from the array, rather than have to hard code the extraction of values into the script for each specific web form I use.
The $ENV hash of PERL does not store the data submitted from a form in name-value keys. It stores environment variables in name-value pairs.

You can create arrays from things in an HTML form, see the PHP FAQ at http://www.php.net/FAQ.php#8.1
     
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status: Offline
Reply With Quote
May 24, 2001, 04:41 PM
 
Originally posted by NeoMac:
It would be much easier to write a script and pull the name-value pairs from the array, rather than have to hard code the extraction of values into the script for each specific web form I use.
There's no "extraction of values" involved in PHP because the form field names become the variable names.

The only time you need to "extract" key-values is when you're dynamically creating forms and variable names can't be "hard coded". In this case, you can name your fields numerically (e.g. field1, field2, etc), then add a hidden field with the number of fields in it. Extraction code would look like:

for ($i=0;$i<$numFields;$i++){
$fieldName="field".$i;
$keyval_array[$fieldName]=${$fieldName};
}

In the above case, $keyval_array["field1"] will have whatever data was entered in field1. (Or it should, it's untested code.)
     
NeoMac  (op)
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 25, 2001, 12:36 AM
 

Angus_D's response solves the problem.

Writing the form values into an array will suffice for my purposes.

Thanks. 'A+' Angus_D.
"Last time the French asked for more evidence, it rolled through France with a German flag." - David Letterman
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:11 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2