cgidata - parse cgidata
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)
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
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>
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
Here is the list of parameters:
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" });
Written by Pierre Laplante, <laplante@sednove.com>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.
1.0 2014-09-09 21:24:14 laplante@sednove.com