Học WordPress + AI / WordPress cho người VIỆT !
WPShare247

Học wordpress cho người mới bắt đầu

  • Bắt đầu
    • Học WordPress
    • Elementor
    • WooCommerce
    • Tạo WordPress
    • Học WordPress kiểu mới 2025
    • Học PHP cơ bản
    • Tạo Website bằng WordPress
    • Quản trị WordPress
    • Sửa lỗi WordPress
    • Theme wordpress
    • Plugin WordPress
    • Hàm PHP
    • Seo WordPress
    • Bảo mật WordPress
    • Html & Css
    • Javascript và jQuery
    • Hướng dẫn lập trình
  • Video
    • Video TikTok
    • Video Shorts
  • Kho plugin
  • Tải Web Miễn Phí
  • Công cụ
    • Kiểm tra web WordPress
    • WordPress theme gì?
    • Check IP Website
    • Kiểm tra Tên Miền
    • Kiểm Tra SSL
    • Tạo File Disavow Google
    • Tạo QR Code
  • Giới thiệu
    • Khuyến Mãi
  • Đăng nhập
X
☰

Trang chủ » Hàm WordPress » Danh sách Hook của Contact Form 7 và Cách sử dụng

📌 Mới: Bạn có thể 🧠 đặt câu hỏi cho AI về nội dung bài viết này ở cuối trang!

Danh sách Hook của Contact Form 7 và Cách sử dụng

Xuất bản vào 18/11/2022 bởi Chinsu Man Xem: 17678
Shares
ChatGPT ChatGPT
Share
Share
Pin

CHƯƠNG TRÌNH GIẢM 50% GIÁ TẤT CẢ CÁC GÓI HOSTING WORDPRESS => Link giảm 50%

Bài viết hướng dẫn có chứa CODE - Copy và sử dụng chúng sẽ tiện hơn cho bạn.

1. Hook form liên hệ Contact Form 7 là gì?

Hook trong WordPress là gì?

Hook là những đoạn code được xây dựng sẵn mà WordPress đã cung cấp cho chúng ta. Hook có 2 loại: Action và Filter. Với Action cho phép chúng ta thêm mới code tại các khu vực do_action thông qua hàm add_action. Còn với Filter sẽ cho phép chúng ta thay đổi kết quả bằng add_filter tại khu vực apply_filters.

Trong plugin contact form 7 đã chuẩn bị sẵn những Hook cho riêng mình, từ đó các bạn có thể thêm mới những chức năng hoặc thay đổi kết quả của plugin này. Sau đây là danh sách các Hook có sẵn, bạn có thể tham khảo nhé.

🌱 Nếu thấy bài viết hữu ích, bạn có thể ủng hộ tác giả bằng cách nhấn vào quảng cáo bên dưới — như một donate miễn phí. Bạn không mất gì nhưng chúng tôi sẽ có thêm chi phí để duy trì và vận hành website. Cảm ơn bạn! 🙏

Trong đó 2 Hook được dùng nhiều hơn cả là trước khi gửi mail: wpcf7_before_send_mail và sau khi đã gửi mail thành công: wpcf7_mail_sent

2. Danh sách các Hook của Contact Form 7

Hook Doc Type File(s)
deprecated_function_trigger_error filter functions.php
wpcf7_acceptance filter submission.php
wpcf7_additional_mail filter submission.php
wpcf7_admin_footer action edit-contact-form.php
wpcf7_admin_init action admin.php
wpcf7_admin_load action admin.php
wpcf7_admin_menu action admin.php
wpcf7_admin_menu_change_notice filter admin.php
wpcf7_admin_misc_pub_section action edit-contact-form.php
wpcf7_admin_notices action edit-contact-form.php, admin.php
wpcf7_admin_warnings action edit-contact-form.php, admin.php
wpcf7_after_create Save action contact-form.php
wpcf7_after_flamingo action flamingo.php
wpcf7_after_save Save action contact-form.php
wpcf7_after_update Save action contact-form.php
wpcf7_ajax_json_echo filter rest-api.php
wpcf7_ajax_onload filter rest-api.php
wpcf7_akismet_comment_check filter akismet.php
wpcf7_autop_or_not filter functions.php
wpcf7_before_send_mail Mail action submission.php
wpcf7_captcha_url filter really-simple-captcha.php
wpcf7_collect_mail_tags filter contact-form.php
wpcf7_config_validator_validate action config-validator.php
wpcf7_constant_contact_contact_post_request_builder filter constant-contact.php
wpcf7_constant_contact_submit filter constant-contact.php
wpcf7_contact_form action contact-form.php
wpcf7_contact_form_default_pack filter contact-form.php
wpcf7_contact_form_properties filter contact-form.php
wpcf7_contact_form_shortcode filter contact-form.php
wpcf7_copy filter contact-form.php
wpcf7_default_template filter contact-form-template.php
wpcf7_display_message filter contact-form.php
wpcf7_editor_panels filter edit-contact-form.php
wpcf7_enqueue_scripts action controller.php
wpcf7_enqueue_styles action controller.php
wpcf7_flamingo_get_value filter flamingo.php
wpcf7_flamingo_submit_if filter flamingo.php
wpcf7_form_action_url Generating Form HTML filter contact-form.php
wpcf7_form_autocomplete Generating Form HTML filter contact-form.php
wpcf7_form_class_attr Generating Form HTML filter contact-form.php
wpcf7_form_elements filter contact-form.php
wpcf7_form_enctype Generating Form HTML filter contact-form.php
wpcf7_form_hidden_fields filter contact-form.php
wpcf7_form_id_attr Generating Form HTML filter contact-form.php
wpcf7_form_name_attr Generating Form HTML filter contact-form.php
wpcf7_form_novalidate Generating Form HTML filter contact-form.php
wpcf7_form_response_output filter contact-form.php
wpcf7_form_tag filter form-tags-manager.php
wpcf7_form_tag_data_option filter form-tag.php
wpcf7_init action settings.php
wpcf7_is_date filter formatting.php
wpcf7_is_email filter formatting.php
wpcf7_is_number filter formatting.php
wpcf7_is_tel filter formatting.php
wpcf7_is_url filter formatting.php
wpcf7_load_css filter functions.php
wpcf7_load_js filter functions.php
wpcf7_log_remote_request filter functions.php
wpcf7_mail_components filter mail.php
wpcf7_mail_failed action submission.php
wpcf7_mail_html_footer filter mail.php
wpcf7_mail_html_header filter mail.php
wpcf7_mail_sent action submission.php
wpcf7_mail_tag_replaced filter mail.php
wpcf7_mail_tag_replaced_{$type} filter mail.php
wpcf7_map_meta_cap filter capabilities.php
wpcf7_messages filter contact-form-template.php
wpcf7_post_edit_form_tag action edit-contact-form.php
wpcf7_posted_data filter submission.php
wpcf7_posted_data_{$type} filter submission.php
wpcf7_recaptcha_actions filter recaptcha.php
wpcf7_recaptcha_threshold filter recaptcha.php
wpcf7_recaptcha_verify_response filter recaptcha.php
wpcf7_remote_ip_addr filter submission.php
wpcf7_save_contact_form action contact-form-functions.php
wpcf7_skip_mail filter submission.php
wpcf7_spam filter submission.php
wpcf7_special_mail_tags filter mail.php, flamingo.php
wpcf7_submission_is_blacklisted filter submission.php
wpcf7_submit action contact-form.php
wpcf7_subscribers_only_notice Generating Form HTML filter contact-form.php
wpcf7_support_html5 filter functions.php
wpcf7_support_html5_fallback filter functions.php
wpcf7_upgrade action settings.php
wpcf7_upload_dir filter functions.php
wpcf7_upload_file_name Validation + upload handling filter add_filter( ‘wpcf7_validate_file’, ‘wpcf7_file_validation_filter’, 10, 2 ); add_filter( ‘wpcf7_validate_file’, ‘wpcf7_file_validation_filter’, 10, 2 ); filter file.php
wpcf7_use_really_simple_captcha filter functions.php
wpcf7_validate filter submission.php
wpcf7_validate_configuration filter functions.php
wpcf7_validate_{$type} filter submission.php
wpcf7_validation_error filter contact-form.php
wpcf7_verify_nonce filter contact-form.php

3. Cách dùng Hook Contact Form 7

Trong ví dụ này tôi sẽ hướng dẫn các bạn một vài hook phổ biến. Các bạn copy các đoạn code sau vào file functions.php nhé.

3.1 Contact form 7 action trước khi gửi mail wpcf7_before_send_mail.

add_action( 'wpcf7_before_send_mail', 'wpshare247_wpcf7_before_send_mail', 10, 3); 
function wpshare247_wpcf7_before_send_mail( $contact_form, &$abort, $object ) { 
    $submission = WPCF7_Submission::get_instance();
    
    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
        
        //Lấy dữ liệu qua các field đã khai báo trong Form [your-name] ; [your-email]......
        $your_name = $posted_data['your-name'];
        $your_email = $posted_data['your-email'];
        
        //Bạn hãy check hay làm cái gì đó ở đây nhé............
        //Ví dụ ----------
        if(strpos($your_email, '@') === false){
            $abort = true;
            
            $mess_err = $your_email." - Email không đúng định dạng vì thiếu @";
            
            $object->set_response($mess_err);
        }
    }
     return $contact_form;
}

3.2 Contact form 7 action sau khi gửi mail thành công wpcf7_mail_sent.

add_action( 'wpcf7_mail_sent', 'wpshare247_wpcf7_mail_sent'); 
function wpshare247_wpcf7_mail_sent( $contact_form ) { 
    $submission = WPCF7_Submission::get_instance();
    if ( $submission ) {
        $contact_form_id = $contact_form->id;
        $posted_data = $submission->get_posted_data();
        
        //Lấy dữ liệu qua các field đã khai báo trong Form [your-name] ; [your-email]...... 
        $your_name = $posted_data['your-name']; 
        $your_email = $posted_data['your-email'];
        $current_post_id = $submission->get_meta('container_post_id');
        
        update_post_meta( $current_post_id, 'your_name', $your_name );
        update_post_meta( $current_post_id, 'your_email', $your_email );
    }
}

Hi vọng bài viết này sẽ hữu ích cho bạn, hãy tiếp tục truy cập để đón đọc các bài viết tiếp theo nhé.

CHƯƠNG TRÌNH GIẢM 50% GIÁ TẤT CẢ CÁC GÓI HOSTING WORDPRESS => Link giảm 50%

❓ Hỏi AI về nội dung bài viết

Tóm tắt nội dung chính Gợi ý mục quan trọng Giải thích mục 1 rõ hơn Viết lại đoạn văn cho dễ hiểu Rút gọn văn bản mà vẫn đủ ý Thêm ví dụ minh hoạ cho đoạn 1 Lọc keyword từ khóa bài viết Lọc thuật ngữ Dịch bài viết sang: Tiếng Anh
Nếu bài viết chưa giải đáp hết thắc mắc của bạn, hãy hỏi WPSHARE247 AI – trợ lý thông minh sẵn sàng hỗ trợ ngay trong nội dung bài viết.

Bạn muốn tích hợp chức năng Hỏi AI trực tiếp dưới mỗi bài viết trên website? Hãy liên hệ dịch vụ thiết kế web tại Website366.com để được hỗ trợ triển khai nhanh chóng và chuyên nghiệp.

Shares
ChatGPT ChatGPT
Share
Share
Pin
← Bài cũ hơn → Bài tiếp theo
add_actionapply_filterapply_filtersContact Form 7hook
Bài viết liên quan
  • Tổng hợp những Plugin WordPress miễn phí đã có tích hợp AI bản Free

    Tổng hợp những Plugin WordPress miễn phí đã có tích hợp AI bản Free

  • Tài liệu hướng dẫn tích hợp AI Gemini trực tiếp vào WordPress thông qua API Google từng bước cụ thể

    Tài liệu hướng dẫn tích hợp AI Gemini trực tiếp vào WordPress thông qua API Google từng bước cụ thể

  • Thử kết nối API trong WordPress cho người mới học code (cập nhật 2025)

    Thử kết nối API trong WordPress cho người mới học code (cập nhật 2025)

  • Tài liệu Hướng Dẫn Upload File Lên WordPress Bằng Ajax Dành Cho Người Mới

    Tài liệu Hướng Dẫn Upload File Lên WordPress Bằng Ajax Dành Cho Người Mới

Học thiết kế Web WordPress

Download WordPress

Tải bản WordPress mới nhất

Tiếng Việt: Tải WordPress Mới

Quốc tế: Tải WordPress Mới

Liên kế MXH của WPShare247

Tìm thấy những kiến thức mới từ WPShare247

Giảm 50% Hosting

Xem chi tiết giảm giá 50% gói lưu trự Hosting tại đây => Link giảm 50%

Cách tạo Web bán hàng Bằng Flatsome

https://www.youtube.com/watch?v=gnT8Dn_KiXU

Video Tiktok mới nhất

@hocwordpress SSL bằng Plug-in Wordpress Really Simple SSL giúp bảo mật đúng cách hơn, tránh tình trạng bảo mật ảo HTTPS #wpshare247 #wordpress #plugin #ssl #https ♬ nhạc nền - Học WordPress - WPSHARE247.COM

Cách tạo Website WordPress 2025

https://www.youtube.com/watch?v=HtbtsH8q-KU

Bộ WIDGETS WS247 Đa Năng

Giúp bạn Thiết kế Website WordPress giống mẫu 99% trong thời gian ngắn nhất (Có bản nâng cấp mới V2). Download tại đây

 

Xem chi tiết tại đây  https://wpshare247.com/chia-se-bo-field-widget-giup-ban-thiet-ke-website-wordpress-nhanh-hon

MUA HOSTING – TẶNG BUỔI HỌC WP

Tặng 03 buổi (Mỗi buổi 30 phút) hỗ trợ miễn phí, tất cả các chuyên đề nào về học thiết kế website bằng WordPress khi mua Hosting và Tên miền => tại đây [ Có thể liên hệ bất cứ giờ nào để hỗ trợ học WP ]

Tôi đang cần...
Cách làm blog Plugin Wordpress Bảo mật Wordpress Seo với Wordpress Lỗi Wordpress WooCommerce

MUA HOSTING – TẶNG BUỔI HỌC WP

Chủ đề

  • Code WordPress
  • Hàm WordPress
  • Hướng dẫn WordPress
  • Theme wordpress
  • WooCommerce
  • Seo WordPress
  • Html & Css
  • Javascript và jQuery
  • Plugin WordPress
  • Hướng dẫn lập trình

Tag

add_action (2) add_filter (2) admin code (2) alt (2) Block Theme (2) cart (4) Contact Form 7 (8) css (4) custom post type (2) cài wordpress (2) danh mục sản phẩm (2) elementor (2) elementor free (2) filter (2) flatsome (2) functions.php (2) google font (2) hosting (2) html css (2) hướng dẫn dùng plugin (4) học wordpress (7) javascript (5) jquery (3) localhost (2) Loop (2) mysql (4) ngôn ngữ (2) phpmyadmin (3) plugin (4) plugin wordpress (2) Product (4) SMTP (2) Sản phẩm (3) Template page (2) theme option (2) Theme Wordpress (3) widget (2) woocommerce (25) wordpress (5) WordPress 2025 (2) wp-config (2) wp_enqueue_scripts (2) WP_Query (6) xampp (4) Yoast SEO (2)
Về WPShare247

Học wordpress cho người mới bắt đầu.

WPShare247 là blog chia sẻ các kiến thức về WordPress, sửa chữa lỗi wordpress, giới thiệu theme và plugin wordpress mới nhất. Đào tạo khóa học thiết kế Website bằng WordPress.

Menu
  • Trang chủ
  • Giới thiệu
  • Blog
  • Plugin WordPress
  • Liên hệ
Chủ đề wordpress
  • Sửa lỗi WordPress
  • Plugin WordPress
  • Theme wordpress
  • Seo WordPress
  • WooCommerce

Copyright © 2025 WPSHARE247. All Rights Reserved.
Một sản phẩm của WEB 366

  • Thiết kế web bởi Website366.com
  • Thiết kế website chuyên nghiệp TBAY.VN
  • Thiết kế website bán hàng