ContactForm7で確認用メールアドレス機能を追加:WordPress
最終更新日:
ContactForm7で確認用メールアドレス機能を追加する方法をメモ
仮にContactForm7のフォーム部品が
[email* your-email placeholder "info@xxxxxx.xxxx"]</p> [email* your-email_confirm placeholder "※確認のためもう一度ご入力ください"]
となっていた場合、
functions.phpに
function wpcf7_main_validation_filter( $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]) { if (method_exists($result, 'invalidate')) { $result->invalidate( $tag,"確認用のメールアドレスが一致していません"); } else { $result['valid'] = false; $result['reason'][$name] = '確認用のメールアドレスが一致していません'; } } } } return $result; } add_filter( 'wpcf7_validate_email', 'wpcf7_main_validation_filter', 11, 2 ); add_filter( 'wpcf7_validate_email*', 'wpcf7_main_validation_filter', 11, 2 );
を追加でOK