[cfdb-value]
This documentation applies to version 2.6
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" format="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 inshowand specify afilterthat 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"]