Data Source for Contact Form 7

描述

Data Source for Contact Form 7 plugin allows populating the “Contact Form 7” fields (text, email, URL, drop-down menu, …) with data stored in external data sources, like a database, CSV file, users information, post data, taxonomies, and JSON objects.

Data Source for Contact Form 7 includes two new controls in the controls bar of Contact Form 7, recordset and recordset field link. The “recordset” control reads the information from the external data source (a database, a CSV file, or any other data source supported), and the “recordset field link” control for linking the recordsets and form fields to populate them with the recordset data.

A form can include several “recordset” fields, and it is possible to link multiple “recordset field link” controls to the same recordset.

How to create the simplest contact form from our practical examples.

Features:

  • Set the information of external data sources available for the Contact Form 7 fields.
  • Easy to use, includes two new controls in the controls bar to define the recordsets and the link fields.
  • Includes the “Users Information” data source to populate the form’s fields with the users’ information.
  • Includes the “Posts Information” data source to populate the form’s fields with the posts’ data, pages, and custom post types (like the WooCommerce products).
  • Includes the “Taxonomy” data source to populate the form’s fields with taxonomy terms, like categories, posts tags, or any other custom taxonomy.
  • Includes the “Database” data source to populate the form’s fields with the information of a database. Allow defining even complex queries.
  • Allows using the fields’ values for filtering the recordset records.

Features in Premium version:

  • All features of the free version of the plugin.
  • Includes the “CSV” data source to populate the form’s fields with the data store into a CSV file.
  • Includes the “JSON” data source to populate the form’s fields with the data store into a JSON file. There are hundreds of services whose outputs are JSON objects.

Data Source Fields

Data Source for Contact Form 7 includes two new controls in the controls bar of Contact Form 7, recordset and recordset field link.

The recordset control reads the information from the external data source and makes it available on the form. A recordset field can read one or many records from the data source.

To insert a recordset field in the form, press the “recordset” button in the controls bar. This action opens a dialog to define the recordset.

The insertion dialog includes common attributes for all data sources and specific attributes for the data source selected.

The “recordset field link” control links a recordset field to other fields in the form to populate them with the recordset data.

To insert a link field in the form, press the “recordset field link” button in the controls bar. This action opens a dialog to define the relationship between a recordset and a form’s field.

The link dialog includes the attributes to define the relationship between the recordset field and the form’s fields.

Cases of Use

Get the information of the registered user and populate the form fields for his name and email:

    <label> Your name [text* your-name] </label>

    <label> Your email [email* your-email] </label>

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

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

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

    [cf7-link-field recordset="cf7-recordset-434" field="your-name" value="first_name"]

    [cf7-link-field recordset="cf7-recordset-434" field="your-email" value="user_email"]

    [submit "Submit"]

Populates the list of WooCommerce products and get the price of the selected one:

    <label>Products List [select menu-719]</label>

    <label>Product Price [number number-534]</label>

    [cf7-recordset id="cf7-recordset-619" type="database" engine="mysql" query="SELECT ID,post_title,meta_value as price FROM {wpdb.posts} posts, {wpdb.postmeta} meta WHERE posts.post_type='product' AND posts.ID=meta.post_id AND meta.meta_key='_regular_price'"]

    [cf7-link-field recordset="cf7-recordset-619" field="menu-719" value="ID" text="post_title"]

    [cf7-link-field recordset="cf7-recordset-619" field="number-534" value="price" condition="record['ID']=={field.menu-719}"]

    [submit "Submit"]

Using Javascript to Access the Recordset Data

The recordset fields trigger the “cf7-recordset” event after receiving the information from the data source, allowing you to access this information with Javascript. In this example, the recordset field reads motivational phrases from a third-party service and displays the first of them into a DIV tag on the form.

螢幕截圖

  • Data Source Controls
  • Recordset Insertion Dialog
  • Recordset Field Link Dialog
  • Data Sources List
  • User Information Data Source
  • Posts Data Source
  • Taxonomies Data Source
  • Database Data Source
  • CSV Data Source
  • JSON Data Source

安裝

To install the Data Source for Contact Form 7 plugin, follow these steps:

  1. Download the .zip file for the Data Source for Contact Form 7 plugin.
  2. Go to the Plugins section on WordPress.
  3. Press the “Add New” button at the top of the plugins section.
  4. Press the “Upload Plugin” button and select the zipped file downloaded in the first step.
  5. Install and activate the plugin.

常見問題

Q: Can I populate any field in the form?

A: Yes, using Link fields, you can use the records in the recordset fields to populate any CF7 field in the form.

Q: Why the “Recordset Field Link” dialog includes an attribute for value and another for text?

A: Fields like number, tel, text area, text, etc. require only the “Attribute for value”

However, CF7 includes other controls like drop-down menus, radio buttons, and checkboxes with multiple choices, where every choice requires a value and text. For these fields, should be populated the attribute for text in the dialog.

Q: What is the condition for filtering attribute in the “Recordset Field Link” dialog?

A: The recordset control read records from the data source, but you might want to populate the form’s fields with only some of these records. The “Condition for filtering” attribute allows filtering the records to use.

Q: Can I use the values of other fields for filtering?

A: Yes, you can. To use the values of other fields for filtering, you should use the format: {field.field-name}

For example, {field.email}, {field.first-name}, {field.last-name}

Q: Can I use the values of javascript variables for filtering?

A: Yes, you can. Similarly to the form’s fields, you can refer to javascript variables using the format: {var.variable-name}

Q: Why some characters change once the recordset or link field is inserted in the form?

A: The plugin encodes some characters because they are not supported by the shortcodes, like the square brackets, double quotes, greater than, and less than symbols.

評價

2021年4月10日
Allows you to use server side data with the CF7 form, like the users information, posts data, taxonomies, and many other data sources.
閱讀全部1個評價

貢獻者及開發者

“Data Source for Contact Form 7” 是一個開源的軟體。以下的人對這個外掛作出了貢獻。

貢獻者

將 Data Source for Contact Form 7 外掛本地化為台灣繁體中文版。

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

修改日誌

1.0.14

  • Improve the plugin interface and user experience.

1.0.13

  • Improves the access to the demos and documentation.

1.0.12

  • Includes the database data source in the free version of the plugin.

1.0.11

  • Includes the path to the error logs files in the plugin interface.

1.0.10

  • Hides the upgrade recommendations for non-administrator users.

1.0.9

  • Triggers events from recordset fields to allow access to the data from javascript.

1.0.8

  • Improves the use experience of the plugin by including access to practical examples.

1.0.7

  • Fixes an issue parsing the javascript variables.

1.0.6

  • Modifies the recordset-field settings to improves the users’ experience.

1.0.5

  • Fixes a warning message.

1.0.4

  • Improves the interface and access to support.

1.0.3

  • Include access to functional demos from the plugin’s interface.

1.0.2

  • Fixes an issue replacing arrays in data sources.

1.0.1

  • Fixes a compatibility issue with PHP 8.

1.0.0

  • First version released.