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,error:variable)
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:
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>
Here is the list of parameters:
res={}. return res={"a":"éé","c":"d"}. with arguments '?a=éé&c=d' res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d' res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d' res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f" res={}. return res={"a":"éé","c":"d","e":"f"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f" res={}. return res={"a":"éé","c":"d","e":"f"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f" res={}. return res={"a":"f,éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f" res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f" res={}. return res={"a":"f","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f" res={}. return res={"a":"f,éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f" res={}. return res={"a":"f;éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f" res={}. 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>
1.0 2014-09-09 21:24:14 laplante@sednove.com
1.2 2014-10-12 laplante@sednove.com Return last result if called twice
1.3 2016-03-08 laplante@sednove.com Add esc_cgidata
Edit© 2024 extenso Inc. All rights reserved.