[cfdb-value]
This documentation applies to version 2.6 and later
Summary of Shortcode Options
Option | Example |
Description |
form | [cfdb-value form="myform"] |
Required. Designates the form to display. All rows and columns are displayed by default |
role | [cfdb-datatable form="myform" role="Author"] |
Make short code only display output for user’s with minimum-required role. Choices are
WARNING: this setting is overridden by plugin setting in WP Admin page Contact -> Database Options -> Can See Submission when using shortcodes |
show | [cfdb-value form="myform" show="col1,col2"] |
Limits columns to be shown to be those designated (comma-delimited list) |
hide | [cfdb-value form="myform" hide="col1,col2"] |
Does not show listed columns (comma-delimited list) |
limit | [cfdb-value form="myform" limit="10"] |
One number: limit=”10″ means show first 10 rows. Is the same as limit=”0,10″ Two Numbers: limit=”100,10″ means show 10 rows starting at row #100) |
random | [cfdb-table form="myform" random="2"] |
Display 2 random rows from those that the short code finds. (Since 2.4) |
orderby | [cfdb-value form="myform" orderby="last-name,first-name"] |
Sort rows by designated columns. Use “column-name desc” to sort in descending (reverse) order |
search | [cfdb-value form="myform" search="Simpson"] |
Select rows to display that have any cell with the search text in it (case insensitive). Intended to mimic behavior of the “Search” field in the DataTable |
filter | [cfdb-value form="myform" filter="col1=Simpson"] |
Select which rows to display based on filter expression. More powerful than “search”, it can filter on multiple columns with boolean and regular expressions. If both “search” and “filter” are specified, “search” is ignored. |
Options specific to this shortcode | ||
function | [cfdb-value form="myform" function="count"] |
Can be: count, min, max, sum, mean, percent.
Use in conjunction with filter and show to select the rows and columns containing the data to input into the function. WARNING: you generally want to pick ONLY ONE row in “show”. If you do not, all returned values will be used. |
delimiter | [cfdb-value form="myform" delimiter="|"] |
When multiple values are returned by the shortcode, by default they are printed with a ‘, ‘ delimiting them. Use this option to change that delimiter. |
Don’t want a table or JSON? Just want to put a value in the page? Use the [cfdb-value]
shortcode
Example:
[cfdb-value form="your-form" show="field1" filter="Submitted Login=$user_login"]
would display the field1 form value for the currently viewing user (who would have needed to be logged in when he submitted…see documentation on $user_login variable substitution).
The intention is to specify one column/field inshow
and specify afilter
that would select on submission. (see how this works for[cfdb-table]
) But if you specify more columns or have more submissions (rows) resulting in the filter, then this shortcode will print out a comma-delimited list of values. You can also usehide
.
count
Count rows: [cfdb-value function="count" form="myform"]
Count entries in column “col1”: [cfdb-value function="count" form="myform" show="col1"]
min
Minimum entry in column “col1”: [cfdb-value function="min" form="myform" show="col1"]
max
Maximum entry in column “col1”: [cfdb-value function="max" form="myform" show="col1"]
Sum of entries in column “col1”: [cfdb-value function="sum" form="myform" show="col1"]
mean
Mean of entries in column “col1”: [cfdb-value function="mean" form="myform" show="col1"]
Available as of version 1.8.4. Specify a delimiter to be put between multiple values. Note: if you are using a function then it will always return one value, so there will never be a delimiter. So ‘function’ and ‘delimiter’ are mutually exclusive.
Example: [cfdb-value form="myform" show="col1" delimiter="|"]
In this case, if there is more than one entry in the DB for this form, all the “col1” values will printed delimited with a “|”, e.g. “submission1-col1|submission2-col1|submission3-col1”
NOTE: if you want more complex formatting of the output, use the [cfdb-html]
shortcode instead.
percent
Returns a percentage value of the (number of form entries matching your show and filter criteria) / (total number of form submissions for the form).
Limitation: this is always a percent of the total number of entries in the database. However, you can create a short code to compute a percentage on a subset of a form’s submissions.
@vbk
If you are writing php code, then you need to call the plugin’s PHP API that the shortcode uses. The code would look like this:
$export = new ExportToValue();
$atts = array ( ‘filter’ => ‘colA=xxx’, show => ‘colA’ );
$html = $export->export(‘NameOfYourForm’, $atts);
where $atts is an associative array of options. Options are the same as the shortcode inputs. I hope this helps
Hi,
I would like to use to use the following short code: [cfdb-value form="contact form" show="mantra" role="Anyone" permissionmsg="true" function="sum"]
But I would like to display it in the widget area. How do I go about doing it?
Hi there,
I’ve managed to solve the problem by adding the following line to functions.php:
add_filter(‘widget_text’, ‘do_shortcode’);
Thanks.
Hi,
How can I get the value of fields in the latest record? What should I put in the filter property?
Many thanks!
Try: [cfdb-value form="form name" limit="1" orderby="submit_time DESC"]
Hi Michael,
Would it be difficult to create a custom function that returns the mode of a specific column? I see from above the only functions that are currently supported are count, min, max, sum, mean and percent. I’m hoping, if say the entries in col1 are “Blue, Green, Black, Blue” to create a function and use a short code like below to return the value “Blue”.
[cfdb-value function="mode" form="myform" show="col1"]
Thanks as always for the help,
Jon
Hi,
I need to pass in a form field a sum of 5 amounts recorded in 5 fields. A shortcode like [cfdb-value form="bilancio" show="cli3+cre3+attfin3+liq3+rata3" filter="username=$user_login"] is it possible? How to do it?
Thank you
Yes. Add function=”sum” to your short code
Thank you. Solved!
I would like to say that this plugin is great. It has made this so much easier for a non-software guy like myself.
I would like to create charts based on the data that gets displayed using the [cfdb-value] shortcode. What would be the easiest way to achieve this?
Thank you
Sean
You would probably want to find some Javascript-based chart library (a bunch of them out there). You would use a short code here like [cfdb-value] or maybe [cfdb-json] to output the data into a javascript variable that you then pass as the data into the chart stuff. The trick is to get the data in the format that the charting library likes.
Thanks for the reply. I am not a coder and have very limited understanding of this type of thing so please bear with me.
I saw this example under the json page:
var mystuff = [the json data];
Is the [the json data] literal? Or does something else go there? I have seen many libraries that seem to fit the bill, but I am uncertain as to how to pass the data from the shortcode.
Thanks for the help.
@SeanW
try a [cfdb-json] with the different format options and look at the page source to see what each puts out. If those are not good, try [cfdb-html] to output the data in exactly the format you want.