8/1/15

Kiểm tra Email không trùng lặp - Contact form 7

Hiện nay Contactfom 7 chưa hỗ trợ kiểm tra trường email có trùng hay không. Và mình có đoạn code này khá hay cùng chia sẻ mọi người.

Để kiểm tra Email có trùng lặp hay không trước tiên chúng ta kiếm một đoạn Jquery kiểm tra Email. và đây là đoạn code:
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// First we trigger the form submit event $('.wpcf7-submit').click(function () { // We remove the error to avoid duplicate errors $('.error').remove(); // We create a variable to store our error message var errorMsg = $('<span role="alert" class="wpcf7-not-valid-tip">メールアドレスを正しく入力してください。</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 ($('.email').find('input').val() !== $('.email-confirm').find('input').val()) { errorMsg.insertAfter($('.email-confirm').find('input')); return false; } else { // If they do match we remove the error and we submit the form $('.error').remove(); return true; } });

Sau đó chúng ta để ở đâu đó và tìm đến file này controller.php

và Tìm đến:  function wpcf7_enqueue_scripts() { ...} này và chèn đoạn code dưới vào:


1
2
3
4
5
function wpcf7_enqueue_scripts() {
.....
wp_enqueue_script( 'email_verification',
wpcf7_plugin_url( 'includes/js/email_verification.js' ),
array( 'jquery', 'jquery-form' ), WPCF7_VERSION, $in_footer ); 

......
}


Sau đó vào Dashboard -> contac form7 --> Thêm Đoạn Đỏ vào.

Vậy là xong.

Tác Giả : Hạnh Đô

0 nhận xét: