Helma logo
helma.org » Home > Stories > req.data

req.data

Object storing HTTP form and environment data as named properties.

Syntax
req.data.propertyname

The req.data object contains values from cookies and form parameters values submitted via a HTTP POST or GET request (Helma treats both methods the same, but you can find out if you are processing a POST or GET request using req.isGet() and req.isPost()).

If more than one value is submitted for one parameter name, the values are stored inside an array called req.data.paramname_array. That is, the _array suffix is added to the parameter name. This is to prevent code which expects just one parameter value to fail unpredictably, and to allow explicit handling of multiple parameter values.

Furthermore, the following HTTP environment variables are automaticall set if they are available:

  • http_browser
    Name and version of the client Browser
  • http_host
    Name of the local server
  • http_remotehost
    Internet address of the client machine
  • http_referer
    URL of the page the user came from
The function get() provides exactly the same functionality in a what we think not as comfortable way (gotta type brackets and quotes). But it's just a matter of taste which one to use. Example
Here we see all three methods of setting a key-value pair:
res.write('<form action=" + root.href("showValues") + " method="post"><input name="city"><input type="submit"></form>');

res.write('<form action=" + root.href("showValues") + " method="get"><input name="district"><input type="submit"></form>');

res.setCookie("street", "Lindengasse");


File root/showValues.hac:
res.write(req.data.city);
res.write(req.data.district);
res.write(req.data.street);


Note: If you have got a cookie and a form element with the same name sent by "get" or "post", the cookie value will be overridden by the form value.


... comment


Page last modified on 2003-10-14 16:46 by hns

 
kmfdm, Wednesday, 5. June 2002, 18:14
File-Uploads
Fileuploads generate a MimePart-Object. This object has a simple method for writing it's content to a file: .writeToFile(pathstring, filename)

For example:
<form action=... method=post enctype="multipart/form-data"> <input type=file name=upload>
</form>


-------

This get's submited to the following hac-file, which just saves this image.

-------
req.data.upload.writeToFile("/tmp", "testfile.dat");

... link  


... comment
 
nex, Monday, 17. February 2003, 14:25
Re: req.data
at the moment the document above says:
The function get() provides exactly the same functionality in a what we think not as comfortable way (gotta type brackets and quotes). But it's just a matter of taste which one to use.
This is wrong. While the object.propertyName syntax requires you to specify the name of a property when you write your code, the get() syntax not only allows a string literal to specify the name of the property, but also a string variable, i.e. with the latter you can get a proper whose name you don't know yet. This is very useful, for example if you extend hopobject with a macro that displays an arbitrary property whose name is given as a parameter of the macro. In this case, you must use the get function, that's not a matter of taste. Please correct!

... link  

 
tobi, Saturday, 22. February 2003, 13:36
Re: Re: req.data
you can do this with req.data, too:
req.data[variableName]

so i think the text is just ok. it remains a question of taste which function to use, even though with a variable as property name you have to type brackets in both cases.

... link  

 
nex, Friday, 21. March 2003, 11:11
oh, sorry
I should wear sackcloth and ashes until I learned how ECMAScript works; didn't know that the notation with the brackets is equivalent. If you want to remove my silly comment and add a hint at the req.data[name] form to the manual, you have my blessing :-)

... link  


... comment