{"id":3700,"date":"2018-12-05T17:26:40","date_gmt":"2018-12-05T17:26:40","guid":{"rendered":"https:\/\/sarcasolutions.com\/?p=3700"},"modified":"2018-12-05T19:32:44","modified_gmt":"2018-12-05T19:32:44","slug":"custom-function-for-_get","status":"publish","type":"post","link":"https:\/\/sarcasolutions.com\/index.php\/2018\/12\/05\/custom-function-for-_get\/","title":{"rendered":"Custom Function for $_GET[]"},"content":{"rendered":"<p>If you&#8217;ve ever worked with Filemaker&#8217;s Insert From URL function, you may have experienced a situation where the external site you are working with insists on returning information as GET (as opposed to POST). This is a custom function that simplifies grabbing the variables returned and formatting them as JSON.<\/p>\n<p><strong>JSONfromGET ( url ) =<\/strong><\/p>\n<p>\/\/ Custom Function to turn variables returned as GET into json<br \/>\n\/\/ Parameter:<br \/>\n\/\/url : the url containing the get variables returned by a web server. From a webviewer, you can use<br \/>\n\/\/ GetLayoutObjectAttribute ( &#8220;nameofwebviewer&#8221; ; &#8220;source&#8221; ) to get the url<\/p>\n<p>Let([<br \/>\n\/\/ count how many variables are in the url by counting &#8220;=&#8221;<br \/>\ncount = PatternCount ( url; &#8220;=&#8221;);<br \/>\nle = Length(url);<br \/>\nlast = Position ( url ; &#8220;=&#8221; ;le ; -1 );<br \/>\nlastsep = Position (url; &#8220;&#038;&#8221;; le; -1 );<br \/>\nstart = Position (url; &#8220;?&#8221;; 0; 1);<\/p>\n<p>\/\/ find the last key,value set<br \/>\nkey = If ( count = 1; Middle (url; start + 1; last &#8211; start -1); Middle (url; lastsep + 1; last &#8211; lastsep &#8211; 1));<br \/>\nvalue = Right ( url; Length(url) &#8211; last);<br \/>\ntype = If (Length(value) = Length(GetAsNumber(value)); &#8220;JSONNumber&#8221;; JSONString);<\/p>\n<p>\/\/ determine if this is the first loop<br \/>\nisJSON = If (Left(url; 1) = &#8220;{&#8220;; 1 ; 0);<br \/>\nJSONstart = If (isJSON; Left(url; Position (url; &#8220;}&#8221;; le; -1)) ;&#8221;{}&#8221;);<br \/>\n\/\/ add the key, value pair to the json<br \/>\njson = JSONSetElement ( JSONstart ; key ; value ; type );<br \/>\n\/\/ strip the key, value pair from the url<br \/>\nnewurl = Middle (url; start; lastsep &#8211; start);<\/p>\n<p>\/\/ if there are more variables to grab, run the function again<br \/>\nresult = If ( count > 1; JSONfromGET(json &#038; newurl) ;<br \/>\njson)<\/p>\n<p>];<\/p>\n<p>result<br \/>\n)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever worked with Filemaker&#8217;s Insert From URL function, you may have experienced a situation where the external site you are working with insists on returning information as GET (as opposed to POST). This is a custom function that simplifies grabbing the variables returned and formatting them as JSON. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-3700","post","type-post","status-publish","format-standard","hentry","category-custom-functions"],"_links":{"self":[{"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/3700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=3700"}],"version-history":[{"count":4,"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/3700\/revisions"}],"predecessor-version":[{"id":3708,"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/3700\/revisions\/3708"}],"wp:attachment":[{"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=3700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=3700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sarcasolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=3700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}