These are functional examples that you can copy and paste directly into your project, in whole or in part.

Some examples are compatible with the free version of the plug-in and others require the commercial version. Each example includes a label indicating the version of the plug-in with which it is compatible.

CF7 Data Source - Practical Examples.

Get details of logged user

Free Version Professional Version

Reads the information of the logged user (login, email, first name, and last name) with the cf7-recordset field [cf7-recordset id="user-data" type="user" attributes="user_login,user_email,first_name,last_name" logged="1"]

<label> User login
[text* user-login] </label>

<label> User email
[email* user-email] </label>

<label> First name
[text first-name] </label>

<label> Last name
[text last-name] </label>

<label> Subject
[text* your-subject] </label>

<label> Your message (optional)
[textarea your-message] </label>

[cf7-recordset id="user-data" type="user" attributes="user_login,user_email,first_name,last_name" logged="1"]

[cf7-link-field recordset="user-data" field="user-login" value="user_login"]
[cf7-link-field recordset="user-data" field="user-email" value="user_email"]
[cf7-link-field recordset="user-data" field="first-name" value="first_name"]
[cf7-link-field recordset="user-data" field="last-name" value="last_name"]

Filling plain texts in the form with the first name and last name of the logged user with the cf7-recordset field [cf7-recordset id="user-data" type="user" attributes="first_name,last_name" logged="1"]

<label> Hello <span id="first-name"></span> <span id="last-name"></span>

[cf7-recordset id="user-data" type="user" attributes="first_name,last_name" logged="1"]

[cf7-link-field recordset="user-data" field="first-name" value="first_name"]
[cf7-link-field recordset="user-data" field="last-name" value="last_name"]

Get first and last name of logged user using templates

Free Version Professional Version

Reads the first and last name of the logged user and uses templates to concatenate them before filling a text field in the form.

<label> First and last name
[text user-name] </label>

[cf7-recordset id="user-data" type="user" attributes="first_name,last_name" logged="1"]

[cf7-link-field recordset="user-data" field="user-name" value="{template.user-name}"]

<template id="user-name">{attribute.first_name} {attribute.last_name}</template>

Users lists and their emails

Free Version Professional Version

Reads the users list (Ids, logins, and emails) with the cf7-recordset field [cf7-recordset id="users-data" type="user" attributes="ID,user_login,user_email"]

Fill in the email field with the email address of the selected user [cf7-link-field recordset="users-data" field="user-email" value="user_email" condition="record&#91;'ID'&#93; == {field.users-list}"]

<label> Users
[select users-list] </label>

<label> User email
[email* user-email] </label>

[cf7-recordset id="users-data" type="user" attributes="ID,user_login,user_email"]

[cf7-link-field recordset="users-data" field="users-list" value="ID" text="user_login"]
[cf7-link-field recordset="users-data" field="user-email" value="user_email" condition="record&#91;'ID'&#93; == {field.users-list}"]

List of published posts

Free Version Professional Version

Get the ids and titles of published posts [cf7-recordset id="posts-data" type="post" attributes="ID,post_title" condition="post_status='publish' AND post_type='post'"]

<label> Posts
[select posts-list] </label>

[cf7-recordset id="posts-data" type="post" attributes="ID,post_title" condition="post_status='publish' AND post_type='post'"]

[cf7-link-field recordset="posts-data" field="posts-list" value="ID" text="post_title"]

List of published posts using a callback function for filtering

Free Version Professional Version

Get the published posts data [cf7-recordset id="posts-data" type="post" attributes="ID,post_title,post_status,post_type"], but list only the published posts by filtering them with a callback function.

<script>
function filtering_records(records){
var processed_records = [];
for(var i in records){
if(records[i]['post_status'] == 'publish' && records[i]['post_type'] == 'post') {
processed_records.push(records[i]);
} }
return processed_records;
}
</script>

<label> Posts
[select posts-list] </label>

[cf7-recordset id="posts-data" type="post" attributes="ID,post_title,post_status,post_type" callback="filtering_records"]

[cf7-link-field recordset="posts-data" field="posts-list" value="ID" text="post_title"]

List of posts titles and excerpts using templates

Free Version Professional Version

Get the titles and excerpts of published posts [cf7-recordset id="posts-data" type="post" attributes="post_title,post_excerpt,guid" condition="post_status='publish' AND post_type='post'"] and display them using templates.

<div id="posts-list"></div>

[cf7-recordset id="posts-data" type="post" attributes="post_title,post_excerpt,guid" condition="post_status='publish' AND post_type='post'"]

[cf7-link-field recordset="posts-data" field="posts-list" value="{template.post-summary}" limit="10"]

<template id="post-summary">
<h2><a href="{attribute.guid}">{attribute.post_title}</a></h2>
<p>{attribute.post_excerpt}</p>
</template>

List of WooCommerce products

Free Version Professional Version

Get the ids and titles of published products [cf7-recordset id="products" type="post" attributes="ID,post_title" condition="post_status='publish' AND post_type='product'"] using the posts data source, and the price of the selected product from database [cf7-recordset id="price" type="database" engine="mysql" query="SELECT meta_value FROM {wpdb.postmeta} WHERE post_id={field.products-list} AND meta_key='_price'"]

<label> Products
[select products-list] </label>

<label> Price
[number product-price] </label>

[cf7-recordset id="products" type="post" attributes="ID,post_title" condition="post_status='publish' AND post_type='product'"]
[cf7-recordset id="price" type="database" engine="mysql" query="SELECT meta_value FROM {wpdb.postmeta} WHERE post_id={field.products-list} AND meta_key='_price'"]

[cf7-link-field recordset="products" field="products-list" value="ID" text="post_title"]
[cf7-link-field recordset="price" field="product-price" value="meta_value" text="post_title"]

List of Departments using Javascript functions

Free Version Professional Version

Get the departments list by calling a Javascript function [cf7-recordset id="departments_data" type="client" function="departments_details"]

<label> Departments
[select departments-list] </label>

<label> Director
[text director] </label>

<label> Contact email
[email email] </label>

<script>
    function departments_details(){
        return [{
          department: 'Marketing',
          director: 'John Doe',
          email: 'marketing@company.com'
          },{
          department: 'I+D',
          director: 'Jane Doe',
          email: 'idg@company.com'
          },{
          department: 'Sales',
          director: 'Jacqueline Smith',
          email: 'sales@company.com'
        }];
    }
</script>

[cf7-recordset id="departments_data" type="client" function="departments_details"]

[cf7-link-field recordset="departments_data" field="departments-list" text="department" value="department"]

[cf7-link-field recordset="departments_data" field="director" value="director" condition="record['department'] == '{field.departments-list}'"]

[cf7-link-field recordset="departments_data" field="email" value="email" condition="record['department'] == '{field.departments-list}'"]

Categories and its posts

Free Version Professional Version

Get the terms in the "Category" taxonomy using the taxonomy data source [cf7-recordset id="category-terms" type="taxonomy" taxonomy="category" attributes="term_id,name"] and the post list associated with the selected term, by using the database data source [cf7-recordset id="posts-list" type="database" engine="mysql" query="SELECT ID,post_title from {wpdb.posts} LEFT JOIN {wpdb.term_relationships} ON ({wpdb.posts}.ID = {wpdb.term_relationships}.object_id) WHERE {wpdb.term_relationships}.term_taxonomy_id = {field.categories}"]

<label> Categories
[select categories] </label>

<label> Posts
[select posts] </label>

[cf7-recordset id="category-terms" type="taxonomy" taxonomy="category" attributes="term_id,name"]
[cf7-recordset id="posts-list" type="database" engine="mysql" query="SELECT ID,post_title from {wpdb.posts} LEFT JOIN {wpdb.term_relationships} ON ({wpdb.posts}.ID = {wpdb.term_relationships}.object_id) WHERE {wpdb.term_relationships}.term_taxonomy_id = {field.categories}"]

[cf7-link-field recordset="category-terms" field="categories" value="term_id" text="name"]
[cf7-link-field recordset="posts-list" field="posts" value="ID" text="post_title"]

Category terms in the current post

Free Version Professional Version

Get the terms in the "Category" taxonomy associated with the post where the form is inserted
[cf7-recordset id="category-terms" type="taxonomy" taxonomy="category" attributes="term_id,name" in="{post.id}"]

<label> Terms
[select terms] </label>

[cf7-recordset id="category-terms" type="taxonomy" taxonomy="category" attributes="term_id,name" in="{post.id}"]
[cf7-link-field recordset="category-terms" field="terms" value="term_id" text="name"]

Country list and details

Professional Version

Uses the CSV data source to read a CSV file with the list of countries and their information [cf7-recordset id="country-data" type="csv" url="https://raw.githubusercontent.com/datasets/country-codes/master/data/country-codes.csv" headline="1" delimiter=","]

It fills the other fields in the form with the data of the country selected.

<label> Country list
[select country-list] </label>

<label> Region name
[text region-name] </label>

<label> Capital
[text capital] </label>

<label> Language
[text language] </label>

[cf7-recordset id="country-data" type="csv" url="https://raw.githubusercontent.com/datasets/country-codes/master/data/country-codes.csv" headline="1" delimiter=","]

[cf7-link-field recordset="country-data" field="country-list" value="official_name_en" text="official_name_en" condition="record&#91;'official_name_en'&#93;!=''"]

[cf7-link-field recordset="country-data" field="region-name" value="Region Name" condition="record&#91;'official_name_en'&#93;==&#34;{field.country-list}&#34;"]

[cf7-link-field recordset="country-data" field="capital" value="Capital" condition="record&#91;'official_name_en'&#93;==&#34;{field.country-list}&#34;"]

[cf7-link-field recordset="country-data" field="language" value="Languages" condition="record&#91;'official_name_en'&#93;==&#34;{field.country-list}&#34;"]

Get stock information from third-party services

Professional Version

Get the stock information from the external service https://www.alphavantage.co by using the JSON data source.

It fills the other fields in the form with the stock data.

<label>Stock Symbol
[text symbol "IBM"]</label>

<label>Open
[text open]</label>

<label>High
[text high]</label>

<label>High
[text low]</label>

<label>Price
[text price]</label>

[cf7-recordset id="stock-data" type="json" url="https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={field.symbol}&apikey=12U67PHYF9R5QVIR"]

[cf7-link-field recordset="stock-data" field="open" value="02. open"]
[cf7-link-field recordset="stock-data" field="high" value="03. high"]
[cf7-link-field recordset="stock-data" field="low" value="04. low"]
[cf7-link-field recordset="stock-data" field="price" value="05. price"]

Get post categories list via server-side data source

Professional Version

Get the list of post category terms by calling a server side function implemented with the "Server Side" add-on.

Server Side Function:

  $GLOBALS['SERVER_SIDE_DATASOURCE']['categories'] = function(){

  $categories_list = [];

  $get_categories = function($term_id = 0, $level = 0) use (&$get_categories, &$categories_list){
    $args = [
        'taxonomy' => 'category',
        'orderby' => 'name',
        'show_count' => true,
        'pad_counts' => false,
        'hierarchical' => true,
        'hide_empty' => false,
        'parent'   => $term_id
      ];
      $categories = get_categories($args);
      foreach ( $categories as $category ) {
        $category->name = str_repeat(" ", $level*2).$category->name;
        $categories_list[] = (array) $category;
        $get_categories( $category->term_id, $level+1);
      }
    };

    $get_categories();
    return $categories_list;
  };

Form structure:

<label>Category list [select category-list]</label>
[cf7-recordset id="category-records" type="server" function="categories"]
[cf7-link-field recordset="category-records" field="category-list" value="term_id" text="name"]