{"id":96,"date":"2011-02-17T13:02:17","date_gmt":"2011-02-17T18:02:17","guid":{"rendered":"http:\/\/cfdbplugin.com\/?page_id=96"},"modified":"2016-12-15T21:55:10","modified_gmt":"2016-12-16T02:55:10","slug":"cfdb-json","status":"publish","type":"page","link":"https:\/\/cfdbplugin.com\/?page_id=96","title":{"rendered":"[cfdb-json]"},"content":{"rendered":"<p><span style=\"font-weight:bold; background-color:#FFFF99;\">This documentation applies to version 2.6 and later<\/span><\/p>\n<h1><strong>Summary of Shortcode Options<\/strong><\/h1>\n<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\" align=\"left\">\n<tbody>\n<tr>\n<td valign=\"middle\" width=\"10%\"><strong>Option<\/strong><\/td>\n<td width=\"40\"><strong>Example<br \/>\n<\/strong><\/td>\n<td width=\"40%\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#form\"><strong>form<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-json <strong>form=\"myform\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Required. Designates the form to display. All rows and columns are displayed by default<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#role\"><strong>role<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-datatable form=\"myform\" <strong>role=\"Author\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Make short code only display output for user&#8217;s with minimum-required role. Choices are<\/p>\n<ul>\n<li>Administrator<\/li>\n<li>Editor<\/li>\n<li>Author<\/li>\n<li>Contributor<\/li>\n<li>Subscriber<\/li>\n<li>Anyone<\/li>\n<\/ul>\n<p><strong>WARNING<\/strong>: this setting is overridden by plugin setting in WP Admin page Contact -> Database Options -> Can See Submission when using shortcodes<br \/>\n(since 2.4.1)\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#show\"><strong>show<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-json form=\"myform\" <strong>show=\"col1,col2\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Limits columns to be shown to be those designated (comma-delimited list)<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#hide\"><strong>hide<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-json form=\"myform\" <span style=\"font-weight: bold;\">hide<\/span><strong>=\"col1,col2\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Does not show listed columns (comma-delimited list)<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#limit\"><strong>limit<\/strong><\/a><\/td>\n<td align=\"left\" valign=\"middle\" width=\"40%\"><code>[cfdb-json\u00a0form=\"myform\"\u00a0<strong>limit=\"10\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">One number: limit=&#8221;10&#8243; means show first 10 rows. Is the same as limit=&#8221;0,10&#8243;<br \/>\nTwo Numbers: limit=&#8221;100,10&#8243; means show 10 rows starting at row #100)<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#random\"><strong>random<\/strong><\/a><\/td>\n<td align=\"left\" valign=\"middle\" width=\"40%\"><code>[cfdb-table form=\"myform\"\u00a0<strong>random=\"2\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Display 2 random rows from those that the short code finds. (Since 2.4)<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#orderby\"><strong>orderby<\/strong><\/a><\/td>\n<td align=\"left\" valign=\"middle\" width=\"40%\"><code>[cfdb-json\u00a0form=\"myform\"\u00a0<strong>orderby=\"last-name,first-name\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Sort rows by designated columns. Use &#8220;column-name desc&#8221; to sort in descending (reverse) order<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#search\"><strong>search<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-json\u00a0form=\"myform\"\u00a0<span style=\"font-weight: bold;\">search<\/span><strong>=\"Simpson\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Select rows to display that have any cell with the search text in it (case insensitive). Intended to mimic behavior of the &#8220;Search&#8221; field in the DataTable<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"http:\/\/cfdbplugin.com\/?page_id=89#filter\"><strong>filter<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-json form=\"myform\" <span style=\"font-weight: bold;\">filter<\/span><strong>=\"col1=Simpson\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Select which rows to display based on filter expression. More powerful than &#8220;search&#8221;, it can filter on multiple columns with boolean and regular expressions. If both &#8220;search&#8221; and &#8220;filter&#8221; are specified, &#8220;search&#8221; is ignored.<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\" valign=\"middle\" width=\"10%\"><em>Options specific to this shortcode<\/em><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><a href=\"#var\"><strong>var<\/strong><\/a><\/td>\n<td width=\"40\"><code>[cfdb-json form=\"myform\" <span style=\"font-weight: bold;\">var<\/span><strong>=\"myJsVar\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Sets the Javascript variable name<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\" width=\"10%\"><strong><a href=\"#format\">format<\/a><\/strong><\/td>\n<td width=\"40\"><code>[cfdb-json form=\"myform\"\u00a0<span style=\"font-weight: bold;\">format<\/span><strong>=\"array\"<\/strong>]<\/code><\/td>\n<td width=\"40%\">Can be &#8220;<strong>map<\/strong>&#8220;, &#8220;<strong>array<\/strong>&#8221; or &#8220;<strong>arraynoheader<\/strong>&#8220;. Default is &#8220;map&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Use <code>[cfdb-json form=\"your-form\"]<\/code> with optional <code>show<\/code>, <code>hide<\/code> and <code>filter<\/code> just like<code>[cfdb-table]<\/code>.<\/p>\n<p>The <code>[cfdb-json]<\/code> works much the same as the <code>[cfdb-table]<\/code> tag but it outputs a <code>&lt;script&gt;<\/code> tag in the HTML in which it set a Javascript variable equal to a JSON representation of the data.<\/p>\n<p><a name=\"var\"><\/a>Use <code>var<\/code> to indicate the name of the javascript variable you would like. For example<span style=\"font-family: monospace;\">:<\/span><code><br \/>\n[cfdb-json var=\"mystuff\"]<\/code><\/p>\n<p>would result in an HTML script tag:<\/p>\n<p style=\"margin-left: 40px;\"><code>&lt;script type=\"text\/javascript\" language=\"JavaScript\"&gt;<br \/>\nvar mystuff = [the json data];<br \/>\n<\/code>&lt;\/script&gt;<\/p>\n<p>Use <code>show<\/code>, <code>hide<\/code>, <code>filter<\/code> options work just as they do for all shortcodes.<\/p>\n<p><a name=\"format\"><\/a><strong>JSON Formats<\/strong><\/p>\n<p>The &#8220;<strong>format<\/strong>&#8221; option provides these options:<\/p>\n<p>&#8220;<strong>map<\/strong>&#8221; is an array of maps (associative arrays).\u00a0Each row is a map of column-name -&gt; value. Each &#8220;cell&#8221; is referenced by<code>jsonVar[row-integer][col-name-string]<\/code>. For example, using\u00a0<code>[cfdb-json var=\"mystuff\"]<\/code> you would be able to reference an example value in Javascript using:\u00a0<code>mystuff[0][\"Submitted\"]<\/code> to refer to the first row, &#8220;Submitted&#8221; column.<\/p>\n<p>Example:<br \/>\n<code style=\"word-wrap: break-word; white-space: code-wrap;\">[<br \/>\n{\"Submitted\":\"December 10, 2010 10:30 am\",\"your-name\":\"Name1\",\"checkbox-311\":\"first\",\"text-940\":\"Field2\"},<br \/>\n{\"Submitted\":\"December 10, 2010 9:54 am\",\"your-name\":\"Alphred\",\"checkbox-311\":\"third\",\"text-940\":\"xxxx\"},<br \/>\n{\"Submitted\":\"November 16, 2010 12:54 pm\",\"your-name\":\"joe\",\"checkbox-311\":\"second\",\"text-940\":\"goodbye\"},<br \/>\n{\"Submitted\":\"November 16, 2010 12:54 pm\",\"your-name\":\"mike\",\"checkbox-311\":\"first\",\"text-940\":\"hello\"}<br \/>\n]<\/code><br \/>\n&#8220;<strong>array<\/strong>&#8221; is a 2D array of the data, with the first row being the column headers.<\/p>\n<p>Example:<br \/>\n<code style=\"word-wrap: break-word; white-space: code-wrap;\">[<br \/>\n[\"Submitted\",\"your-name\",\"checkbox-311\",\"text-940\"],<br \/>\n[\"December 10, 2010 10:30 am\",\"Name1\",\"first\",\"Field2\"],<br \/>\n[\"December 10, 2010 9:54 am\",\"Alphred\",\"third\",\"xxxx\"],<br \/>\n[\"November 16, 2010 12:54 pm\",\"joe\",\"second\",\"goodbye\"],<br \/>\n[\"November 16, 2010 12:54 pm\",\"mike\",\"first\",\"hello\"]<br \/>\n]<\/code><br \/>\n&#8220;<strong>arraynoheader<\/strong>&#8221; is the same as &#8220;array&#8221; but without the first header row. Is is a 2D array of just the data.<\/p>\n<p>&nbsp;<\/p>\n<p>Example:<br \/>\n<code style=\"word-wrap: break-word; white-space: code-wrap;\">[<br \/>\n[\"December 10, 2010 10:30 am\",\"Name1\",\"first\",\"Field2\"],<br \/>\n[\"December 10, 2010 9:54 am\",\"Alphred\",\"third\",\"xxxx\"],<br \/>\n[\"November 16, 2010 12:54 pm\",\"joe\",\"second\",\"goodbye\"],<br \/>\n[\"November 16, 2010 12:54 pm\",\"mike\",\"first\",\"hello\"]<br \/>\n]<\/code><\/p>\n<h4>How to make an AJAX call to get JSON<\/h4>\n<p>NOTE: the URLs below changed in version 1.8. The 1.8+ URLs are now shown below.<\/p>\n<p>The quick way to see what URL you need to make an AJAX, go to the Database admin page and export to type JSON. Then look at the URL in the browser. It will be of the following form (in this example our form name is &#8220;Form Name&#8221; so we have to use &#8220;Form+Name&#8221; in the URL:<\/p>\n<p><code>http:\/\/mywordpress.com\/wp-admin\/admin-ajax.php?action=cfdb-export&amp;form=Form+Name&amp;enc=JSON&amp;format=map<\/code><\/p>\n<p><strong>Issues<\/strong>: you will run into problems if you not logged in when making this AJAX call because WordPress will redirect you to the login form page. To get past that, you need to use the URL for the login page with a <code>redirect_to<\/code> parameter that gives the URL that you would have wanted above. The problem is that you have to URL-encode the parameters in that URL.<\/p>\n<p>In other words, Example: (You will have to substitute <code>EncodedFormName<\/code> below for the URLEncoded name of your form)<\/p>\n<p><code>http:\/\/mywordpress.com\/wp-admin\/admin-ajax.php?action=cfdb-export&amp;form%3DEncodedFormName%26enc=JSON%26format%3DFarray <\/code><\/p>\n<p>NOTE: You can also append <code>show<\/code>, <code>hide<\/code>, <code>search<\/code> and <code>filter<\/code> to the URL<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary of Shortcode Options Option Example Description form Required. Designates the form to display. All rows and columns are displayed by default role Make short code only display output for user&#8217;s with minimum-required role. Choices are Administrator Editor Author Contributor Subscriber Anyone WARNING: this setting is overridden by plugin setting in WP Admin page Contact [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1577,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"page-without-sidebar.php","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"class_list":["post-96","page","type-page","status-publish","hentry"],"jetpack_shortlink":"https:\/\/wp.me\/P1mptf-1y","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":47,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/96\/revisions"}],"predecessor-version":[{"id":1238,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/96\/revisions\/1238"}],"up":[{"embeddable":true,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/1577"}],"wp:attachment":[{"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}