function

cgidata . string . sncode

VERSIONlatest parse cgidata

CGIDATA

NAME

cgidata - parse cgidata

SYNOPSIS

cgidata(parse_get : true|false, parse_post : true|false, conflict : replace|array|keep|join, join : "join string", callback : "…", postmax : integer, disable_upload : true|false, directory : "directory upload", fileconflict : "overwrite | rename | error", maxsize : 456, extention : "jpg,png,gif", ct : "format/gif, image/jpeg", "file parameter" : { directory : "directory upload to overwrite default directory upload", url : "url….", fileconflict : "overwrite|rename|error", maxsize : 456, ct : …, extention : …}, esc_cgidata:bool)

DESCRIPTION

This function is used to read parameters passed threw cgidata. The parameters can be GET or POST. By default all parameters are read and return as an associative array.

This function can only be called once per request. If the function ia called twice, then the previous result is return even if the arguments are not the same.

cgidata can be used to read data with content-type of

  • application/x-www-form-urlencoded
  • multipart/form-data
  • application/json. In this case, a string will be return and if it is valid JSON, you can use unstringify to get the actual JSON.

When an input type file has the parameters multiple, then name parameter will be an array of image transmit by the form. This feature is available with version 5.73.

An example of application/x-www-form-urlencoded is the following:

Note: In the followings examples, the _ between the { should be removed to make it work.

json.sn:

{_{
        a = cgidata();
        if a.s != undefined then
                b=unstringnify(a.s);
                ret = { error : 0 };
                ret.msg = "No error with " .+ b.userName;
                ret;
        else
                include("json2.sn");
        endif
}}

json2.sn:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
    <script language="javascript" src="jquery.js"></script>
</head>
<body>
        <h1>Json test</h1>
        <p>This test is used to test exchange between sncode and js with json</p>
        <p>A form is used to send a json request and the answer if sent back in json</p>
        <a href="#" onClick="send();">Execute</a>
        <script language="javascript">
                function send() {
                        var userName = "laplante";
                        var password = "pierre";
                        var a = JSON.stringify({ "s":"t","userName": userName, "password" : password });
                         $.ajax ({
                                 type: "POST",
                                 url: '?s='+a,
                                 dataType: 'json',
                                 async: false,
                                 success: function (data) {
                                         alert("Thanks!" + data.error + " " + data.msg);
                                 }
                         })
                }
                $(document).ready(function() {
                });
        </script>
</body>
</html>

Json test

This test is used to test exchange between sncode and js with json

A form is used to send a json request and the answer if sent back in json

Execute

PARAMETERS

Here is the list of parameters:

PARSE_GET
Determine if we parse get. By default, this value is true. GET parameters in HTTP is what is passed on the URL.
CT
Limit upload to those Content-type. Multiple Content-type can be specify separated by a comma.
CALLBACK
This option define a function that can be used as a callback while reading data from post data for upload file. The function is called while reading with the following parameters:
  • maxsize:64000 maxsize allowd
  • finish:false upload for this file is finish or not
  • nbupload:1 nbupload so far
  • size:0 size so far
  • totalsize:31903 total size of all upload
CONFLICT
Determine how to resolve conflict in variable name. Possible value are:
  • replace
  • array
  • keep
  • join
JOIN
Specify joing string. Default is comma : ,.
POSTMAX
Integer value for maximum number of allowed byte in post. Default specify in configuration file.
DISABLE_UPLOAD
Make sure upload are not allowed. true by default.
DIRECTORY
Specify directory where to upload file. /tmp by default.
FILE PARAMETER
Specify where to upload this file. No default value. If no value is specify, parameter directory is used. Parameter URL is to to build the return value sn_url and sn_fullurl which are return.
 
ESC_CGIDATA
If this parameter is true, that all data read by cgidata will be escape. < will be replace by &lt;, > will be replace by &gt; and & will be replace by &amp; Also, the original value
of a paramerer (without escaping) will be put in the name of the parameter prefix by sn_. So if the parameter is call test than cgidata.test will contain the escape value sn sn_test
will contain the original value. This parameter if valid from version 5.48 of sncode. See also configuration parameter esc_cgidata. By default the value of this parameter is false
unless esc_cgidata is true in the configuration file.

RETURN

An associative array of each parameters. For a filename the following will be return: - filename : initial filename. - sn_size : size of filename in bytes. - sn_filename : new name in case of conflict. - sn_dir : directory where the file has been uploaded. - sn_path : directory where the file is save - sn_fullname : sn_path/sn_filename - sn_url : url for the file - sn_fullurl : sn_url / sn_filename - … : others parameters passed with the file. Exemple: ct for content type.

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

res={_{a=cgidata(); a;}}. return res=\{"a":"éé","c":"d"}. with arguments '?a=éé&c=d'
res={_{a=cgidata(); a;}}. return res=\{"a":"éé","c":"d"}. with arguments 'a=éé&c=d'
res={_{a=cgidata(parse_get:false); a;}}. return res=\{"a":"éé","c":"d"}. with arguments 'a=éé&c=d'
res={_{a=cgidata(parse_get:false); a;}}. return res=\{"a":"éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f"
res={_{a=cgidata(); a;}}. return res=\{"a":"éé","c":"d","e":"f"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f"
res={_{a=cgidata(parse_get:true); a;}}. return res=\{"a":"éé","c":"d","e":"f"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f"
res={_{a=cgidata(parse_get:true); a;}}. return res=\{"a":"f,éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={_{a=cgidata(parse_get:true,conflict:"replace"); a;}}. return res=\{"a":"éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={_{a=cgidata(parse_get:true,conflict:"keep"); a;}}. return res=\{"a":"f","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={_{a=cgidata(parse_get:true,conflict:"join"); a;}}. return res=\{"a":"f,éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={_{a=cgidata(parse_get:true,conflict:"join",join:";"); a;}}. return res=\{"a":"f;éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={_{a=cgidata(parse_get:true,conflict:"array"); a;}}. return res=\{"a":\["f","éé"\],"c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
a = cgidata(image : { directory : "/tmp", fileconflict : "error" });

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>