Quantcast
Channel: Takayuki Miyoshi – Contact Form 7
Viewing all 161 articles
Browse latest View live

Contact Form 7 3.7.1

$
0
0

I have released Contact Form 7 3.7.1. Bundled jquery.form.js has been updated to fix an issue with IE8. Upgrading quickly is recommended.



Requires: WordPress 3.6 or higher
Tested up to: WordPress 3.8.1

» Download Contact Form 7 plugin from WordPress.org

Change Log


Contact Form 7 3.7.2

$
0
0

Contact Form 7 3.7.2 has just been released. This release includes a fix for a bug that allows to avoid CAPTCHA validation. Upgrading quickly is recommended especially if you have CAPTCHAs in forms.



Requires: WordPress 3.6 or higher
Tested up to: WordPress 3.8.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Fixed a bug that allowed to avoid CAPTCHA validation.
  • The jQuery Form Plugin (jquery.form.js) has been updated to 3.50.0.
  • Translation for Dutch (Tim de Hoog) has been updated.

Contact Form 7 3.8

$
0
0

Contact Form 7 3.8 is now available. Now you can generate a drop-down menu with hundreds of options (like countries list) by just adding an option to a form-tag. Accessibility has been further improved. Compatible with WordPress 3.9. Also includes several bug fixes and improvements.



Requires: WordPress 3.7 or higher
Tested up to: WordPress 3.9

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Introduced data option for select, checkbox and radio form-tags. With Listo plugin, you can make a menu with hundreds of options.
  • Accessibility improvement: add an invisible response message block before <form>.
  • Added relative date notation support in min and max options of date form-tags.
  • Added html_name attribute support in [contact-form-7] shortcodes.
  • WordPress 3.7 or higher is required.
  • Translation for Ukrainian (Myroslava Pabyrivska) has been updated.

Contact Form 7 3.8.1

$
0
0

Contact Form 7 3.8.1 is now available. This release includes a fix for the Akismet module; that called old functions deprecated in Akismet 3.0. It also includes a few translation updates.



Requires: WordPress 3.7 or higher
Tested up to: WordPress 3.9.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Fix: misuse of functions that Akismet 3.0 has marked deprecated.
  • Fix: some URL outputs used esc_url_raw in places where esc_url should be used.
  • Translation for Finnish (Jani Alha) and Thai (TG Knowledge) have been updated.

Contact Form 7 3.9 Beta

$
0
0

Contact Form 7 3.9 is going to be released shortly. In 3.9, I have done much refactoring for its internal structure. Although most users don’t necessarily need this, if you are a developer of add-on plugins for Contact Form 7 or you have customized Contact Form 7 from your theme’s functions.php file, you may need to modify your code to make it workable with Contact Form 7 3.9.


You can download Contact Form 7 3.9-beta from WordPress.org plugin directory. Testing your code with the beta release before Contact Form 7 3.9 is officially released is highly recommended. If you notice that the add-on plugin you are using stops working after upgrading to Contact Form 7 3.9, please inform the author of the add-on plugin that it needs fixes in order to work with Contact Form 7 3.9.

Major changes made in 3.9 are:

  • The WPCF7_Submission, WPCF7_Mail and WPCF7_MailTaggedText classes have been introduced
  • Some properties and methods have moved from the WPCF7_ContactForm class to the three new classes
  • Visibility of some properties and methods has changed to private. This means the properties and methods are no longer accessible directly from your code

In practice, you will need to modify your code like this:


/* Don't do this, since id property is no longer accessible. */
$id = $contact_form->id; // Wrong.

/* Use id() method instead. */
$id = $contact_form->id();

/* Properties form, mail, mail_2, messages, additional_settings are inaccessible as well. */
$form = $contact_form->form; // Wrong.

/* So, use prop() method to access them. */
$form = $contact_form->prop( 'form' );

/* To set the properties, use set_properties() method, like this: */
$mail = $contact_form->prop( 'mail' );
$mail['subject'] = "Well, hello, Dolly";
$contact_form->set_properties( array( 'mail' => $mail ) );

/* WPCF7_ContactForm object no longer has a posted_data property. */
$posted_data = $contact_form->posted_data; // Wrong.

/* Use WPCF7_Submission object's get_posted_data() method to get it. */
$submission = WPCF7_Submission::get_instance();

if ( $submission ) {
	$posted_data = $submission->get_posted_data();
}

Contact Form 7 3.9

$
0
0

Contact Form 7 3.9 is now available. As stated in the 3.9 beta release, there is plenty of internal restructuring in 3.9. If you are using add-on plugins for Contact Form 7 or have customized Contact Form 7 from your theme’s functions.php file, they might not work correctly after upgrading to 3.9.

If you experience problems, I suggest first deactivating all of the add-on plugins and restoring your own customization. If an add-on plugin appears to be the cause of your issue, please contact the author of the plugin (not me!).



Requires: WordPress 3.8 or higher
Tested up to: WordPress 3.9.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • A major change has been made to the internal structure. For details, see beta release announcement.
  • The exclude_blank mail option has been introduced.
  • The wpcf7_load_js and wpcf7_load_css (functions and filter hooks) have been introduced.
  • The jQuery Form Plugin (jquery.form.js) has been updated to 3.51.0.
  • Translations for Persian (Ghaem Omidi) and Slovak (WordPress Slovakia) have been updated.
  • WordPress 3.8 or higher is required.

Contact Form 7 3.9.1

$
0
0

Contact Form 7 3.9.1 is now available. This release includes a few bug fixes and translation updates.



Requires: WordPress 3.8 or higher
Tested up to: WordPress 3.9.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Fix: options with empty values didn’t work correctly in a drop-down menu.
  • Fix: broke layout of input fields after validation by an incorrect jQuery use.
  • Fix: couldn’t enqueue JavaScript manually with wpcf7_enqueue_scripts() when WPCF7_LOAD_JS was false.
  • Fix: couldn’t enqueue CSS manually with wpcf7_enqueue_styles() when WPCF7_LOAD_CSS was false.
  • Translations for Greek (John D. Dimoferlias) and Hungarian (Farkas Győző) have been updated.

Contact Form 7 3.9.2

$
0
0

Contact Form 7 3.9.2 is now available. This release includes a couple of bug fixes, security enhancement and translation updates. Also, Contact Form 7 3.9.2 has been tested on WordPress 4.0 RC1.



Requires: WordPress 3.8 or higher
Tested up to: WordPress 4.0

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Fixed: incorrect behavior seen in demo mode.
  • Fixed: Flamingo saved submitter’s contact info even when the submission was spam.
  • New: Introduce wpcf7_skip_mail filter.
  • Enhancement: add a random-named directory to each uploaded file’s temporary file path in order to make the path harder for a submitter to guess.
  • Translation for Punjabi has been created by Jasvinder Sing.
  • Translations for Turkish (Burak Yavuz), Korean (martian36) and Slovak (WordPress Slovakia) have been updated.

Contact Form 7 3.9.3

$
0
0

I have just released Contact Form 7 3.9.3 for fixing a bug introduced in the previous version which prevents forms from uploading files in some of server environments. Upgrading quickly is recommended especially if you have file uploading fields in your forms.



Requires: WordPress 3.8 or higher
Tested up to: WordPress 4.0

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Fixed: file uploading was disabled in some of server environments because of wrong use of mt_rand() function. Props oivindmo.
  • Translations for Hungarian (Farkas Győző) has been updated.

Contact Form 7 4.0

$
0
0

Contact Form 7 4.0 is now available. The default mail template changed following best practice. This release also includes some minor fixes, improvements and translation updates.



Requires: WordPress 3.9 or higher
Tested up to: WordPress 4.0

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • The default mail template changed (see Best Practice to Set Up Mail).
  • Translations for Slovak (WordPress Slovakia), German (Ivan Graf), Turkish (Burak Yavuz) and Portuguese (Pedro Mendonça) have been updated.
  • WordPress 3.9 or higher is required.

Contact Form 7 4.0.1

$
0
0

I’ve just released Contact Form 7 4.0.1. Contact Form 7 4.0, which has been released this week, had a bug that caused an error when creating new contact forms in some environments. This release fixes the bug.



Requires: WordPress 3.9 or higher
Tested up to: WordPress 4.0

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Fixed a bug that caused an error when creating new contact forms in some environment.
  • Translations for Portuguese (Pedro Mendonça) and Croatian (Marko Puskaric) have been updated.

Contact Form 7 4.0.2

$
0
0

Contact Form 7 4.0.2 is now available. This release includes a couple of bug fixes, security enhancement and translation updates. Upgrading quickly is recommended.



Requires: WordPress 3.9 or higher
Tested up to: WordPress 4.0.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Introduced wpcf7_build_query() to correctly apply urlencode to keys and values in URL queries.
  • Translations for Portuguese (Pedro Mendonça), Spanish (Carlos Oropesa), Hungarian (Farkas Győző), and German (Ivan Graf) have been updated.

Contact Form 7 4.0.3

$
0
0

Contact Form 7 4.0.3 is now available. The contextual help tab has been added to admin pages. Some translations have been updated. Also, Contact Form 7 4.0.3 has been tested on WordPress 4.1 RC1.



Requires: WordPress 3.9 or higher
Tested up to: WordPress 4.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • The contextual help tab has been added to admin pages.
  • Changed the admin menu icon to “email” dashicon.
  • Translations for Croatian (Marko Puskaric), Turkish (Burak Yavuz), and Catalan (luba lee) have been updated.

Contact Form 7 4.1 Beta

$
0
0

Contact Form 7 4.1 is going to be released soon. In 4.1, I’ve reconstructed the user-input validation process to require less coding and result in fewer errors. If you are a developer of Contact Form 7 add-on plugins that add custom validation, you might need to modify your code to make it work with Contact Form 7 4.1.


You can download Contact Form 7 4.1-beta from the WordPress.org plugin directory. Testing your code with the beta before Contact Form 7 4.1 is officially released is highly recommended. If you notice that the add-on plugin you are using stops working after upgrading to Contact Form 7 4.1, please inform the author of the plugin.

In Contact Form 7 4.1, the WPCF7_Validation class has been introduced, and the $result parameter passed through validation filter functions is now an instance of the WPCF7_Validation class (it was previously a multi-dimensional associative array).

The WPCF7_Validation class implements the ArrayAccess interface, so its instances are supposed to be able to accept array-access as if they are normal arrays. Unfortunately, there seems to be a defect in PHP’s ArrayAccess implementation because an ArrayAccess instance can’t be accessed multi-dimensionally.

If you have a code like this in your add-on:


if ( $condition_of_invalidity ) {
	$result['valid'] = false;
	$result['reason'][$name] = wpcf7_get_message( 'blar_blar' ); // this line causes an error.
}

You need to modify it like so to make it continue working in Contact Form 7 4.1 and later:


if ( $condition_of_invalidity ) {
	$result['valid'] = false;
	$result['reason'] = array( $name => wpcf7_get_message( 'blar_blar' ) );
}

If you don’t mind backward compatibility with Contact Form 7 4.0.x or older, you can make it simpler by using the invalidate() method of the WPCF7_Validation class:


if ( $condition_of_invalidity ) {
	$result->invalidate( $name, wpcf7_get_message( 'blar_blar' ) );
}

Adding A Custom Form-Tag

$
0
0

This is the first entry in a series of articles to help developers customize Contact Form 7.

The first topic is expanding Contact Form 7’s form-tags. As you probably know, form-tags are code in a specific format within square brackets, usually representing form controls like text input fields and submit buttons. Currently, Contact Form 7 supports 30 different types of form-tags by default.

These are examples of typical form-tags:

[text* your-name]
[textarea your-message]
[submit "Send"]

They look like WordPress shortcodes, but unlike shortcodes, form-tags only work within a Contact Form 7 form area.

You can add your own custom form-tags as well. There are two steps to add custom form-tags: (1) register form-tag types and a corresponding callback function, and (2) define the callback function. Let’s look at each step.

wpcf7_add_shortcode

To register form-tag types, call wpcf7_add_shortcode() function. wpcf7_add_shortcode() accepts three parameters (two required and one optional).

The first parameter is a string value containing the type of the tag. The first word in a form-tag is its type. In the examples presented above, “text*”, “textarea”, and “submit” are types. You can use lower-case letters ([a-z]), digits ([0-9]), underscores (“_“), and asterisks (“*“) in a form-tag type. Tag types with a trailing asterisk (e.g., “text*”, “email*”) are used for required input fields.

If you have two or more form-tag types sharing the same callback function, you may want to register them together. In such cases, specify an array of strings as the first parameter.

The second parameter is a callback function called when Contact Form 7 parses the form-tag. More on callback functions later.

The third parameter is an optional Boolean value (default: false). If the form-tag has a name part, set this to true. The name of a form-tag (if it has a name) is the second word in the form-tag. In the examples above, “your-name” and “your-message” are names. Some form-tags don’t have names, like [submit "Send"].

Note that you have to use wpcf7_init action hook when you call wpcf7_add_shortcode(). For reference, see how Contact Form 7 registers default form-tags.

add_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );

function wpcf7_add_shortcode_text() {
	wpcf7_add_shortcode(
		array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
		'wpcf7_text_shortcode_handler', true );
}

Callback Function

The next step is defining the callback function, which only receives a parameter that is an array containing components (type, name, options, values, etc.) of an actual form-tag.

The callback function must return a text value. Usually they return HTML snippets that represent a form control. The returned text replaces the form-tag when Contact Form 7 generates a form from a form template containing form-tags.

As a demonstration, let’s create a simple form-tag that displays the current time (let’s call it “[clock]”).

Add the following code at an appropriate place. Many developers prefer to use theme’s functions.php file for small custom coding. Don’t directly edit files in the plugin (contact-form-7) folder because you risk breaking the plugin code, and you’ll lose your customization when the plugin is updated.

add_action( 'wpcf7_init', 'custom_add_shortcode_clock' );

function custom_add_shortcode_clock() {
	wpcf7_add_shortcode( 'clock', 'custom_clock_shortcode_handler' ); // "clock" is the type of the form-tag
}

function custom_clock_shortcode_handler( $tag ) {
	return date_i18n( get_option( 'time_format' ) );
}

Then, add this line to your form area:

Current Time: [clock]

If it works correctly, you should see a line like this in the form:

Current Time: 12:16 pm

That’s it. Obviously this “[clock]” demo is too simple for practical use, but it’s enough to show the concept of the Contact Form 7 form-tags. To improve and make it suitable for practical use, you’ll need to learn:

  • How to retrieve information from form-tag components and construct more complex form controls using this information.
  • How to validate user input, and if it’s invalid, how to show a validation error.

Upcoming recipes will cover these areas.


Contact Form 7 4.1

$
0
0

Contact Form 7 4.1 is now available. The maxlength and minlength options, and a new type of form-tag for a Twitter-like character count have been introduced. You can now get field default values from GET and POST variables as well as custom field values.

As stated in the 4.1 beta release, there has been a change in the user-input validation process and, if you use add-on plugins or custom code for Contact Form 7, you may need to modify the code to make it work with Contact Form 7 4.1.

This release also includes several bug-fixes, security enhancements, and translation updates. Upgrading quickly is recommended.



Requires: WordPress 4.0 or higher
Tested up to: WordPress 4.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Added maxlength and minlength options to several form-tag types.
  • Added [count] form-tag type that represents character count for form fields.
  • Introduced WPCF7_Validation class to handle the user-input validation process.
  • Added the front-end URL normalization for [url] fields.
  • Added default:get, default:post and default:post_meta options to get default values from the context.
  • Translations for Turkish (Burak Yavuz), German (Ivan Graf), Portuguese (Pedro Mendonça), Dutch (Tim de Hoog), and Hebrew (Ahrale) have been updated.
  • WordPress 4.0 or higher is required.

Using Values from A Form-Tag

$
0
0

The previous recipe illustrated how you can add custom form-tags simply. In this recipe, you’ll learn how to retrieve values from a form-tag and use those values in the HTML output in a form.

We are going to create a custom form-tag that represents an input field with an associated datalist. Datalist is a new element introduced in HTML5; it provides a list of predefined options for an input field associated with a datalist.

The following listing shows an example HTML markup for a text input field and a datalist.

<input name="currency" type="text" list="currency-options" />
<datalist id="currency-options">
	<option>U.S. Dollars ($)</option>
	<option>Euros (€)</option>
</datalist>

In this example, the list attribute of the input element and the id attribute of the datalist element share the same value (“currency-options”), thus the two elements are associated with each other.

This input field expects a currency name. While you can type an arbitrary currency name here, it provides “U.S. Dollars ($)” and “Euros (€)” as predefined options because they are the most likely answers.

Screenshot of an example datalist.

Designing a Form-Tag

Let’s design the form-tag for an input field with a datalist. First, you need to decide the type of form-tag. Let’s name it “datalist”.

You can see three variables in the HTML markup in the listing above: the name attribute value (“currency” in the example), the list and id attribute values (“currency-options”), and the option element contents (“U.S. Dollars ($)” and “Euros (€)”).

The list and id attributes need to have the same value, and it doesn’t matter what that value is (as long as it is valid as an id value). If the value can be automatically defined, say, by adding a suffix -options to the name attribute value, you can reduce the number of variables. Now, you only have to define the name attribute value and option element contents in the form-tag.

For the name attribute value, let’s use the name part (the second word) in a form-tag because it’s commonly used for the name attribute value in other form-tag types of Contact Form 7.

For the option element contents, since the contents are likely to be in a free format, using the values part (quoted strings; the final part) in a form-tag is suitable.

See also: How Tags Work

To sum up these design decisions, the following simple form-tag should be able to represent the example HTML markup in the listing above:

[datalist currency "U.S. Dollars ($)" "Euros (€)"]

Let’s start coding to implement this form-tag.

Implementing the Form-Tag

First, register the “datalist” form-tag type with wpcf7_add_shortcode() function. Unlike the [clock] form-tag that we saw in the previous recipe, this tag has a name part so you need to set the third argument of wpcf7_add_shortcode() to true.

add_action( 'wpcf7_init', 'custom_add_shortcode_datalist' );

function custom_add_shortcode_datalist() {
	wpcf7_add_shortcode( 'datalist', 'custom_datalist_shortcode_handler', true );
}

Then, define the callback function that generates HTML output.

function custom_datalist_shortcode_handler( $tag ) {
	$tag = new WPCF7_Shortcode( $tag );

	$atts = array(
		'type' => 'text',
		'name' => $tag->name,
		'list' => $tag->name . '-options' );

	$input = sprintf(
		'<input %s />',
		wpcf7_format_atts( $atts ) );

	$datalist = '';

	foreach ( $tag->values as $val ) {
		$datalist .= sprintf( '<option>%s</option>', esc_html( $val ) );
	}

	$datalist = sprintf(
		'<datalist id="%1$s">%2$s</datalist>',
		$tag->name . '-options',
		$datalist );

	return $input . $datalist;
}

The $tag argument, which is passed to the callback function as its only parameter, is originally a multi-dimensional associative array composed of given form-tag components. A WPCF7_Shortcode object wraps it up to make it easy to handle. The WPCF7_Shortcode object generated at the beginning of the function is used throughout the function.

In this function, you first create the input element. There, you set the necessary attributes (type, name, and list) as items of an array ($atts), and then using wpcf7_format_atts() function, you generate a formatted attribute string. Using wpcf7_format_atts() is recommended because it properly escapes values to provide a secure output.

Then, you build the datalist element that contains child option elements with the values from the form-tag. Finally, the input and datalist elements are concatenated and returned as the result of this function.

That’s it. This form-tag is still too simple and doesn’t even provide user-input validation. Upcoming recipes will deal with validation.

Contact Form 7 4.1.1

$
0
0

Contact Form 7 4.1.1 is now available. This release includes a security enhancement and translation updates. Upgrading quickly is recommended.



Requires: WordPress 4.0 or higher
Tested up to: WordPress 4.1.1

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Security enhancement: use wp_rand() instead of mt_rand() for CAPTCHA file name generation to make it harder for attackers to predict its next value.
  • Modified wpcf7_plugin_url(): use plugins_url() internally.
  • Translations for Russian, Hungarian, Swedish, German, and Turkish have been updated.

Custom Validation

$
0
0

Contact Form 7 provides several kinds of user-input validation by default, including:

  • Is a required field filled in?
  • Does an email field have an email address in the correct format?
  • Is an uploaded file in an acceptable file type and size?

You can also add your own custom validation.

To demonstrate how to implement a custom validation, let’s make an email confirmation field. This field prompts you to input the email address that you input in the other field on the form. The two email addresses you’ve input are compared and if they are not identical, a validation error message will be displayed to alert you.

Contact Form 7 doesn’t support email confirmation fields by default (Because I think it’s ridiculous. Who wants to type the same address twice? People know copy and paste). Still, it can be a good example of custom validation.

Validation as a Filter

In Contact Form 7, a user-input validation is implemented as a filter function. The filter hook used for the validation varies depending on the type of form-tag and is determined as: wpcf7_validate_ + {type of the form-tag}. So, for text form-tags, the filter hook wpcf7_validate_text is used. Likewise, wpcf7_validate_email* is used for email* form-tags.

Let’s say you have the following email fields in a form:

Email:         [email* your-email]
Confirm email: [email* your-email-confirm]

The following listing shows code that verifies whether the two fields have identical values.

add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );

function custom_email_confirmation_validation_filter( $result, $tag ) {
	$tag = new WPCF7_Shortcode( $tag );

	if ( 'your-email-confirm' == $tag->name ) {
		$your_email = isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
		$your_email_confirm = isset( $_POST['your-email-confirm'] ) ? trim( $_POST['your-email-confirm'] ) : '';

		if ( $your_email != $your_email_confirm ) {
			$result->invalidate( $tag, "Are you sure this is the correct address?" );
		}
	}

	return $result;
}

Two parameters will be passed to the filter function: $result and $tag. $result is an instance of WPCF7_Validation class that manages a sequence of validation processes. $tag is an associative array composed of given form-tag components; as you saw in the previous recipe, you can use WPCF7_Shortcode class to handle this type of data.

Look through the inside of the filter function. First, check the name of the form-tag to ensure the validation is applied only to the specific field (your-email-confirm).

The two email field values are then compared, and if they don’t match, $result->invalidate() will be called. You need to pass two parameters to the invalidate() method: the first parameter should be the $tag variable, and the second parameter is the validation error message that you want the field to display.

Lastly, don’t forget to return the $result.

Contact Form 7 4.1.2

$
0
0

Contact Form 7 4.1.2 is now available. This release includes some accessibility improvements and translation updates. Contact Form 7 4.1.2 is compatible with WordPress 4.2.



Requires: WordPress 4.0 or higher
Tested up to: WordPress 4.2

» Download Contact Form 7 plugin from WordPress.org

Change Log

  • Added role="form" to wrapper div elements.
  • Added wrapping label elements to quiz question strings.
  • Translation for Portuguese has been updated.
Viewing all 161 articles
Browse latest View live