[cfdb-value]

December 15th, 2016

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

  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber
  • Anyone

WARNING: this setting is overridden by plugin setting in WP Admin page Contact -> Database Options -> Can See Submission when using shortcodes
(since 2.4.1)

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.

  • count
  • min
  • max
  • sum
  • mean
  • percent (as of 2.0.1)

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.

Functions

 

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

 

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"]

 

delimiter

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.

 

 

 

  1. vbk
    February 20th, 2011 at 13:51 | #1

    vbk :
    Hi,
    First, I thank you for creating this awesome plugin. These short codes are really useful. I need to call a php function in a particular form and I want to use a form field value in that function. Before or after inserting form fields into the database, I need to call that function. I’m not expert in wordpress, I don’t know how to find the form id or form name and a particular field value in the coding. I just want to add a function in a form without disturbing the Plugin codes which is very much needful for me.
    Please help me how to find the form field value. Once again I thank you very much for giving this plugin .
    [ In Forum, comments are closed so i posted here]

  2. msimpson
    February 26th, 2011 at 15:38 | #2

    @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

  3. Witoyo
    January 23rd, 2013 at 01:34 | #3

    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?

  4. Witoyo
    January 23rd, 2013 at 02:34 | #4

    Hi there,

    I’ve managed to solve the problem by adding the following line to functions.php:

    add_filter(‘widget_text’, ‘do_shortcode’);

    Thanks.

  5. Minh Nguyen
    May 16th, 2013 at 14:13 | #5

    Hi,

    How can I get the value of fields in the latest record? What should I put in the filter property?

    Many thanks!

    • Michael Simpson
      May 16th, 2013 at 15:01 | #6

      Try: [cfdb-value form="form name" limit="1" orderby="submit_time DESC"]

  6. jasnon
    October 15th, 2013 at 20:41 | #7

    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

  7. c.gabriele
    November 13th, 2013 at 16:11 | #8

    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

    • Michael Simpson
      November 14th, 2013 at 14:13 | #9

      Yes. Add function=”sum” to your short code

  8. c.gabriele
    November 16th, 2013 at 03:00 | #10

    Thank you. Solved!

  9. SeanW
    June 10th, 2014 at 08:05 | #11

    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

    • Michael Simpson
      June 10th, 2014 at 08:41 | #12

      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.

  10. SeanW
    June 11th, 2014 at 09:37 | #13

    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.

  11. Michael Simpson
    June 11th, 2014 at 22:18 | #14

    @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.

Comments are closed.  Go To Support Forum