Contact Form 7 5.6 Beta

Contact Form 7 5.6 is scheduled for release on June 17. Since 5.6 brings large changes, we are releasing 5.6 Beta for testing.

You can download a copy of the beta version from the GitHub repository. If you find any bugs in it, please report back to us by creating an issue on GitHub.

If you find any add-on plugin or theme that does not work correctly with Contact Form 7 5.6 Beta, then please report the issue to the developers of that product, not to us. We cannot take any responsibility for third-party products.

Introduction of Schema-Woven Validation

The main feature of 5.6 is the introduction of Schema-Woven Validation. This means that a single schema can rule user input validation, both on the server side and on the client (browser) side. Also, since the schema is distributed via WordPress REST API, it opens a way to let you validate user inputs on a web server even if the server is not the origin of the form.

Contact Form 7 5.6 supports 15 rule types for the schema, which correspond to traditional validation filters that older versions of Contact Form 7 support, and future versions are going to add more rule types. Maybe some “composite rules” that enable multistep forms or conditional logic will also appear soon.

To developers: the existing filter-based validation mechanism will continue to work. If you have created custom validation filters, you don’t need to modify them (they only work for the server-side validation, though).

The wpcf7_support_html5 filter hook is deprecated

The wpcf7_support_html5 filter hook is marked as “deprecated” in Contact Form 7 5.6, and will be completely removed in the near future.

This hook was created nine years ago, when Contact Form 7 3.4 introduced form-tags for HTML5 input types. By hooking a callback function that returns false, you could suppress the use of the HTML5 input types.

Now the HTML5 input types are widely accepted and there is no reason to avoid using them, so the wpcf7_support_html5 filter hook should no longer be in use.

File type option supports MIME types

You can now use MIME types to declare acceptable file types for a file-uploading field, as in the following example:

[file file-123 filetypes:image/*|txt|application/pdf]
This field accepts all image files, text and PDF files.

A MIME type used in the filetypes option must be one of the types WordPress defines in wp_get_mime_types(), or one that uses a wildcard (*) in its subtype part (such as image/*).

As with File API, MIME types are not directly used for file-type validation. That means validators won’t read the bytestream of a file to determine its media type. Instead, MIME types are converted to file extensions, and the file extensions are used to validate.

Contact Form 7 5.6 also changes the default filetypes option that is used when you omit the option. The new default filetypes option value is audio/*|video/*|image/*.

Markup changes in form controls

For more consistent DOM manipulation, the HTML markup for form controls has changed slightly. The changes will not affect most users, but if you are a developer of an add-on plugin or a theme that styles forms, you may need to pay attention.

The new markup adds the data-name="{field name}" attribute to a form-control wrapper element (wpcf7-form-control-wrap), and, in favor of it, removes the {field name} class from the element.

Old markup:

<span class="wpcf7-form-control-wrap your-name">
    <input class="wpcf7-form-control wpcf7-text" type="text" name="your-name" />
</span>

New markup:

<span class="wpcf7-form-control-wrap" data-name="your-name">
    <input class="wpcf7-form-control wpcf7-text" type="text" name="your-name" />
</span>

Other major changes

  • Number fields: Accepts decimal number inputs.
  • Config-validator: Accepts an empty value for Cc, Bcc, and Reply-To as a valid email header.
  • Messages: Some default messages for validation errors have changed to use more natural wordings.
  • Introduces WPCF7_ContactForm::is_false().
  • WPCF7_FormTagsManager::filter() supports the basetype condition.
  • Introduces wpcf7_exclude_blank().
  • Replaces some $_SERVER['SERVER_NAME'] references with hostnames derived from network_home_url().
  • REST API: Returns a 415 HTTP error status when the Content-Type header value in a feedback creation request is not multipart/form-data.
  • Introduces WPCF7_Submission::get_posted_string().
  • WPCF7_Validation::invalidate() accepts a WP_Error object.
  • Validation logic has changed in wpcf7_is_url(), wpcf7_is_tel(), and wpcf7_is_number().
  • Uses the shutdown action hook instead of template_redirect.

You can browse the full list of changes on GitHub.