IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. CMS
  4. Wordpress
  5. How to keep and display contact form 7 data

How to keep and display contact form 7 data

2022-04-15 265 Views 1 Like 0 Comments

Display Form Data

Almost every website has its own forms, such as contact form, book form, and registry form... Instead of just submitting the form through email, we want to store the form data for the future inconvenience. Here's an example usage of it.

forms
Online forms

Display form data for certain users

form-data-displayed

Contact Form DB plugin (version >2.4.1)

Contact Form 7 is a useful and easy-to-use WordPress plugin. However, after it sends an email the information disappeared. A plugin called "Contact Form DB" can help persist the form data and provide a shortcode to display the data in a data grid format.

Once the "Contact Form DB" is activated, it created two data tables: wp_cf7dbplugin_st (storing time key) and wp_cf7dbplugin_submits (storing form data).

form-data-tables

In WordPress Dashboard, click on the Contact Form DB button on the left side menu. It would show all form data in a table.

form-data-grid

Under the Contact Form DB button, there is a Shortcode button, it allows you to generate a shortcode of your choice. You could specify a form and the display format and columns to display.

form-data-shortcode

shortcode-types

The following shortcodes are provided:

  • [cfdb-datatable]
  • [cfdb-table]
  • [cfdb-json]
  • [cfdb-value]
  • [cfdb-count]
  • [cfdb-html]

shortcode-columns

Shortcode details

Basic Shortcode

You have a form named “myform” and you want to display all its rows and columns in a page or post:

  • [cfdb-table form="myform"]

Choose Columns to Display with “show” and “hide”

  • [cfdb-table form="myform" show="f1,f2,f3"] (optionally show selected fields)
  • [cfdb-table form="myform" hide="f1,f2,f3"] (optionally hide selected fields)

“show” and “hide” supports regular expressions to be able to specify column names. Regular expression match according to preg-match.

Examples:

  • [cfdb-table form="myform" show="/.*name/"] (shows all fields whose name ends with “name” such as “first-name” and “last-name”)
  • [cfdb-table form="myform" show="/.*name/i"] (Same as previous, but is a case-insensitive match. So “Last-Name” as well as “last-name” match)
  • [cfdb-table form="myform" hide="/Submitted.*/"] (Don’t show fields starting with “Submitted”)
  • [cfdb-table form="myform" hide="message,/Submitted.*/,/Cookie.*/"] (Don’t show (1) the “message” field, (2)  fields starting with “Submitted”, (3) fields starting with “Cookie”. If you have the option on to capture users’ Cookies with their form submissions, use hide=”/Cookie.*/” to hide them. )
  • Remember that is you have both “show” and “hide” specified, any field that match both will be hidden. That is, “hide” trumps “show”.

Specify who can view

The “role” attribute can limit the short code to only create output for logged-in users with a minimal user role. Set the “role” attribute to one of:

  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber
  • Anyone (users do not have to be logged in to see the short code output)

Example: if role="Editor" is used, then a logged in Author, Contributor or Subscriber sees no output. A logged in Editor or Administration will see the output.

Notes:

  • Case Counts. Be sure to capitalize the first letter of the role names
  • If you set permissionmsg="true" then an error message will show on your page when a user does not have permission. By default, if “role” is being used, no permission error is shown.

Limit Rows to Display

Say you just want the first 10 rows, not every form submission. Use “limit”

  • [cfdb-table form="myform" limit="10"] (shows only the first 10 rows)
  • [cfdb-table form="myform" limit="20,10"] (shows only the first 10 rows starting with row #20. In other words, this shows rows #20-29. The previous example shows rows #10-19. So this is like the next page of 10 rows.

Sort data

By default, the results are returned in order of their submission date descending. In other words, the most recent submission entry is first, followed by the next most-recent and so on. But you may want to sort by last name for example. In that case use “orderby”.
In these examples, assume there are columns (form fields) named “lastname” and “firstname”
  • [cfdb-table form="myform" orderby="lastname desc,firstname desc"] (Reverse-sort by lastname and for those with the same lastname, reverse-sort by firstname)

You can use “asc” for ascending sort or “desc” for descending sort. But “asc” is assumed if not specified.

Which Rows to Display

The search field acts like the dynamic Search field that appears on the DataTable. It selects rows where any cell contains the search text (case in-sensitive).

  • [cfdb-table form="your-form" search="Washington"] (show only rows where any field contains “Washington” . Same as "columnName like '%Washington%'" in where clause in SQL.)

Filter provides a much more specific and complex way to specify rows to show. Unlike “search”, “filter” specifies searches on specific columns.

  • [cfdb-table form="your-form" filter="field1=value1"] (show only rows where field1=value1)
  • [cfdb-table form="your-form" filter="field1=null"] (SPECIAL CASE: ‘null’ is interpreted as null-value (field does has no value)
  • [cfdb-table form="your-form" filter="field1!=value1"] (show only rows where field1!=value1)
  • [cfdb-table form="your-form" filter="field1=value1&&field2!=value2"](Logical AND the filters using ‘&&’)
  • [cfdb-table form="your-form" filter="field1=value1||field2!=value2"](Logical OR the filters using ‘||’)
  • [cfdb-table form="your-form" filter="field1=value1&&field2!=value2||field3=value3&&field4=value4"](Mixed &&, ||. Standard Boolean operator precedence applies (ANDs are evaluated, then ORs)
  • [cfdb-table form="your-form" filter="field1~~/^a/"] (Regular expression; shows rows where field1 starts with ‘a’)

Filtering Rows: Supported Filter Operators

  • = and == are the same
  • !=, <> are the same
  • >, <, <=, >=
  • === and !==
  • ~~ for regular expressions
  • [in], [!in] for “in list” such as:
    • filter"=lastname[in]Simpson,Smith,Jones"

Filtering Rows: Filter by Regular Expressions

  • Use the ~~ operator, and Perl-style delimiters around the pattern, such as /
  • [cfdb-table form="your-form" filter="field1~~/^a/"] (shows rows where field1 starts with ‘a’)
  • [cfdb-table form="your-form" filter="field1~~/.*@gmail.com/i"] (shows rows where field1 is a Gmail address, case-insensitive)
  • FYI: uses preg_match to evaluate the regex

Filtering Rows: How to make “filter” Work Like “search”

Given “search” example:

  • [cfdb-table form="your-form" search="Washington"] (Searches ALL fields)

When using “filter” use regular expressions with case-insensitive option (“i”), listing all fields.

  • [cfdb-table form="your-form" filter="field1~~/.*washington.*/i||field2~~/.*washington.*/i"] (searches field1 and field2. You have to put a regex search for all the fields you want to search when using “filter”, strung together with logical ORs “||” )

Filtering Rows: Filter Limitations

  • Does not support parentheses to control the order of boolean evaluation

Filtering based on Relative Time Using submit_time

For the “submit_time” field only, you can use special time values like:

  • [cfdb-table form="your-form" filter="submit_time>last week"] (shows all submissions since last week)

More information

For more detail information on shortcode building for Contact Form DB read official site.

 1,056 total views,  4 views today

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: None
Last updated:2022-04-15

IT Team

This person is lazy and left nothing

Like
< Previous
Next >

Comments

Cancel reply
Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
MySQL urlencode/urldecode that support chinese chars Automation report and validating Fixing image issue in posts How to automatically translate a website to any language WP Plugin "User Specific Content" review Adding reCaptcha for user forms in WordPress
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com