私はこれを正確に検索していましたが、別の方法でうまく機能しました。Contact Form-7 フィールドに以下のように 2 つのフィールドを作成します。
[email* email placeholder "Email"]
[email* email-confirm placeholder "Confirm Email"]
以下の php コードをコピーして functions.php ファイルに貼り付けます
function register_scripts() {
if ( !is_admin() ) {
// include your script
wp_enqueue_script( 'email-confirm', get_bloginfo( 'template_url' ) . '/js/email-confirm.js' );
}
}
add_action( 'wp_enqueue_scripts', 'register_scripts' );
ファイルパスを一致するように変更し、以下のコードを含む js ファイルをそのパス ディレクトリにアップロードしてください。
// First we trigger the form submit event
jQuery( document ).ready( function () {
jQuery('.wpcf7-submit').click(function () {
// We remove the error to avoid duplicate errors
jQuery('.error').remove();
// We create a variable to store our error message
var errorMsg = jQuery('<span class="error">Your emails do not match.</span>');
// Then we check our values to see if they match
// If they do not match we display the error and we do not allow form to submit
if (jQuery('.email').find('input').val() !== jQuery('.email-confirm').find('input').val()) {
errorMsg.insertAfter(jQuery('.email-confirm').find('input'));
return false;
} else {
// If they do match we remove the error and we submit the form
jQuery('.error').remove();
return true;
}
});
} );
私は自分のサイトでそれを使用しており、正常に動作しています。これが私のような人に役立つことを願っています。
参照: Contact Form 7 メールの確認