◆確認用にメールアドレスを2回入力させ、尚且つチェックする機能
1:まずfunction.phpに下記の記述を追加します。
<?php
/* custom contactform7 */
add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter_extend', 11, 2 );
add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter_extend', 11, 2 );
function wpcf7_text_validation_filter_extend( $result, $tag ) {
$type = $tag['type'];
$name = $tag['name'];
$_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
if ( 'email' == $type || 'email*' == $type ) {
if (preg_match('/(.*)_confirm$/', $name, $matches)){
$target_name = $matches[1];
if ($_POST[$name] != $_POST[$target_name]) {
$result['valid'] = false;
$result['reason'][$name] = 'メールアドレスが一致しません';
}
}
}
return $result;
}
?>
2:次にフォームの設定では下記のように
[email* your-email] [email* your-email_confirm]
※透かし文字を入れる場合は
[email* your-email] [email* your-email_confirm watermark"確認のため再度ご入力ください"]