{"id":116,"date":"2011-02-17T13:52:00","date_gmt":"2011-02-17T18:52:00","guid":{"rendered":"http:\/\/cfdbplugin.com\/?page_id=116"},"modified":"2014-10-18T19:17:54","modified_gmt":"2014-10-18T23:17:54","slug":"filter-variable-substitution","status":"publish","type":"page","link":"https:\/\/cfdbplugin.com\/?page_id=116","title":{"rendered":"Filter Variable Substitution"},"content":{"rendered":"<p>This page is a continuation of documentation of the &#8220;filter&#8221; attribute of shortcodes. <a href=\"http:\/\/cfdbplugin.com\/?page_id=89\">First see this page<\/a>.<\/p>\n<h2>Identifying Logged-in User<\/h2>\n<p>If the user is logged in when viewing the page with the shortcode, you can try to match a filter value against some user information. If the user was logged in when he submitted the form, then &#8216;Submitted Login&#8217; will be captured (since version 1.4.4) So if the user is also logged in to view a page with this shortcode, you could have the table filter to show him only his submissions using:<\/p>\n<ul>\n<li><code>[cfdb-table form=\"your-form\" filter=\"Submitted Login=$user_login\"]<\/code><\/li>\n<\/ul>\n<p>Similarly, if the user entered his email in a form field, (say &#8220;email&#8221;), and perhaps was not logged in but entered the same email address as is associated with his WordPress account, then later came back to view a page when logged in, you could show him his entry using:<\/p>\n<ul>\n<li><code>[cfdb-table form=\"your-form\" filter=\"email=$user_email\"]<\/code><\/li>\n<\/ul>\n<p>All of the following variables are supported<\/p>\n<ul>\n<li><code>$user_login<\/code><\/li>\n<li><code>$user_email<\/code><\/li>\n<li><code>$first_name<\/code> or\u00a0<code>$user_firstname<\/code><\/li>\n<li><code>$last_name<\/code> or\u00a0<code>$user_lastname<\/code><\/li>\n<li><code>$user_nicename<\/code><\/li>\n<li><code>$id<\/code> or\u00a0<code>$ID<\/code><\/li>\n<\/ul>\n<h2>Using HTTP GET, POST and COOKIE variables<\/h2>\n<p>When viewing a page or post, you can add HTTP GET parameters on the URL, for example the URL to view post #85 might be:<\/p>\n<ul>\n<li><code><a rel=\"nofollow\" href=\"http:\/\/mywordpress.com\/?p=85\">http:\/\/mywordpress.com\/?p=85<\/a><\/code><\/li>\n<\/ul>\n<p>to which you could add some arbitrary parameter:<\/p>\n<ul>\n<li><code><a rel=\"nofollow\" href=\"http:\/\/mywordpress.com\/?p=85&amp;email=joe@nowhere.com\">http:\/\/mywordpress.com\/?p=85&amp;email=joe@nowhere.com<\/a><\/code><\/li>\n<\/ul>\n<p>in this case you might want to use that\u00a0<code>email=joe@nowhere.com<\/code> in the shortcode filter. Assuming the table you are querying has a field named &#8216;contact_email&#8217;, you could use the shortcode:<\/p>\n<ul>\n<li><code>[cfdb-table form=\"your-form\" filter=\"contact_email=$_GET(email)\"]<\/code> This looks for form submissions where the submitted value for the form&#8217;s contact_email field is equal to\u00a0<a href=\"mailto:joe@nowhere.com\">joe@nowhere.com<\/a>.<\/li>\n<\/ul>\n<p>This syntax can be used:<\/p>\n<ul>\n<li><code>$_GET(http_get_parameter)<\/code> for URL parameters as described above or forms posting to the page on which the shortcode is located, where the form uses method=GET<\/li>\n<li><code>$_POST(http_post_parameter)<\/code> for forms posting to the page on which the shortcode is located, where the form uses method=POST<\/li>\n<li><code>$_COOKIE(http_cookie_name)<\/code> to reference Cookies.<\/li>\n<\/ul>\n<h3><span style=\"font-size: 13px; font-weight: normal;\"> WARNING PHP programmers: note the syntax and don&#8217;t get confused with similar PHP syntax:<\/span><\/h3>\n<ul>\n<li><code>$_GET(value)<\/code> <strong>not<\/strong> <code>$_GET['value']<\/code><\/li>\n<li><code>$_POST(value)<\/code> <strong>not<\/strong> <code>$_POST['value']<\/code><\/li>\n<li><code>$_COOKIE(value)<\/code> <strong>not<\/strong> <code>$_COOKIE['value']<\/code><\/li>\n<\/ul>\n<p>Summary of differences from PHP syntax:<\/p>\n<ul>\n<li>Parentheses are used instead of square brackets because the shortcode already has brackets and we can&#8217;t nest them within it.<\/li>\n<li>Quoting &#8216;value&#8217; is not necessary since you are already quoting the shortcode attribute, and this would result in nested quotes.<\/li>\n<\/ul>\n<h2>Problems when using $_GET<\/h2>\n<h3>1. &#8216;name&#8217; Issue<\/h3>\n<p>Avoid using\u00a0<code>'name'<\/code> as a GET parameter. This example will not work:<\/p>\n<ul>\n<li><code><a rel=\"nofollow\" href=\"http:\/\/mywordpress.com\/?page_id=128&amp;name=admin\">http:\/\/mywordpress.com\/?page_id=128&amp;name=admin<\/a><\/code> WILL NOT WORK!!<\/li>\n<\/ul>\n<p>this gives you a page with the error:<\/p>\n<ul>\n<li><code>Apologies, but the page you requested could not be found. Perhaps searching will help.<\/code><\/li>\n<\/ul>\n<p>The problem is with using\u00a0<code>name<\/code>. Use something else, like\u00a0<code>name1<\/code> and use\u00a0<code>$_GET(name1)<\/code> in your filter. In WordPress, your URL does not go directly to the page, it goes to\u00a0<code><a rel=\"nofollow\" href=\"http:\/\/mywordpress.com\/\">http:\/\/mywordpress.com\/<\/a><\/code> in this example and that takes the parameters and dispatches it to the appropriate page\/post etc. So you have to choose GET parameters names that do not conflict with those that WordPress uses. &#8220;name&#8221; is such a conflict. I don&#8217;t a list of all conflicts, but look for the above error.<\/p>\n<h3>2. Using a Form with method=&#8221;GET&#8221; to post to your page with table<\/h3>\n<p>Imagine this scenario:<\/p>\n<ul>\n<li>(<strong>start<\/strong>) You create a page with a form on it where users input parameters<\/li>\n<li>(<strong>end<\/strong>) That form posts to another page (or same page) that has a shortcode using $_GET in the filter<\/li>\n<\/ul>\n<p>If the URL to your <strong>end <\/strong>page already has a URL parameter in it, then you need to add it to your form as a hidden field. For example, your <strong>end <\/strong>page URL is http:\/\/mysite.com\/?p=246<\/p>\n<p>Then on your start page, you need to add that &#8220;p&#8221; as a hidden parameter, for example:<\/p>\n<h4>Using GET: start page:<\/h4>\n<p><code>&lt;form action=\"<strong>http:\/\/mysite.com\/<\/strong>\" method=\"<strong>GET<\/strong>\"&gt;<br \/>\n<strong>&lt;input type=\"hidden\" name=\"p\" value=\"246\/&gt;<\/strong><br \/>\nField1: &lt;input name=\"f1\"\/&gt; &lt;br\/&gt;<br \/>\nField2: &lt;input name=\"f2\"\/&gt; &lt;br\/&gt;<br \/>\n&lt;input type=\"submit\"\/&gt;<br \/>\n&lt;\/form&gt;<\/code><\/p>\n<h4>Using GET: end page<\/h4>\n<p><code>[cfdb-datatable form=\"myform\" filter=\"Field1=$<strong>_GET<\/strong>(f1)&amp;&amp;Field2=$<strong>_GET<\/strong>(f2)\"]<\/code><\/p>\n<h3 style=\"margin-top:1em;margin-bottom:0.5em\">But if you use &#8220;POST&#8221;, then you don&#8217;t have this problem:<\/h3>\n<h4><strong>Using POST: start page:<\/strong><\/h4>\n<p>Note the <strong>p=246<\/strong> is in the action URL, unlike the &#8220;GET&#8221; example.<br \/>\n<code>&lt;form action=\"http:\/\/mysite.com\/<strong>?p=246<\/strong>\" method=\"<strong>POST<\/strong>\"&gt;<br \/>\nField1: &lt;input name=\"f1\"\/&gt; &lt;br\/&gt;<br \/>\nField2: &lt;input name=\"f2\"\/&gt; &lt;br\/&gt;<br \/>\n&lt;input type=\"submit\"\/&gt;<br \/>\n&lt;\/form&gt;<\/code><\/p>\n<h4>Using POST: end page:<\/h4>\n<p><code>[cfdb-datatable form=\"myform\" filter=\"Field1=$<strong>_POST<\/strong>(f1)&amp;&amp;Field2=$<strong>_POST<\/strong>(f2)\"]<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page is a continuation of documentation of the &#8220;filter&#8221; attribute of shortcodes. First see this page. Identifying Logged-in User If the user is logged in when viewing the page with the shortcode, you can try to match a filter value against some user information. If the user was logged in when he submitted the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1069,"menu_order":10,"comment_status":"closed","ping_status":"closed","template":"page-without-sidebar.php","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"class_list":["post-116","page","type-page","status-publish","hentry"],"jetpack_shortlink":"https:\/\/wp.me\/P1mptf-1S","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/116","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=116"}],"version-history":[{"count":17,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/116\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/116\/revisions\/431"}],"up":[{"embeddable":true,"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=\/wp\/v2\/pages\/1069"}],"wp:attachment":[{"href":"https:\/\/cfdbplugin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}