programing

송신하기 전에 연락처 폼7에 접속하는 방법

bestcode 2023. 2. 10. 21:57
반응형

송신하기 전에 연락처 폼7에 접속하는 방법

연락 양식 7과 대화하고 싶은 플러그인이 있습니다.플러그인에서 다음 액션을 추가했습니다.add_action

add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");

function wpcf7_do_something_else(&$wpcf7_data) {

    // Here is the variable where the data are stored!
    var_dump($wpcf7_data);

    // If you want to skip mailing the data, you can do it...
    $wpcf7_data->skip_mail = true;

}

컨택 폼을 제출했지만 add_action은 아무것도 하지 않았습니다.Contact Form 7에서 작업을 수행할 때 플러그인을 가로채거나 작업을 수행하는 방법을 잘 모르겠습니다.아니, 어떻게 하는지 도와줄까?

이메일이 전송되지 않도록 해야 했습니다.도움이 됐으면 좋겠다.

/*
    Prevent the email sending step for specific form
*/
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");  
function wpcf7_do_something_else($cf7) {
    // get the contact form object
    $wpcf = WPCF7_ContactForm::get_current();

    // if you wanna check the ID of the Form $wpcf->id

    if (/*Perform check here*/) {
        // If you want to skip mailing the data, you can do it...  
        $wpcf->skip_mail = true;    
    }

    return $wpcf;
}

이 코드는 몇 달 전 코드를 리팩터링하기 위해 사용하던 최신 버전의 CF7을 실행하고 있는 것을 전제로 하고 있습니다.[2015년 4월 28일]

WPCF7 5.2 이후로는wpcf7_before_send_mail훅이 많이 바뀌었어요.참고로 5.2+에서 이 훅을 사용하는 방법은 다음과 같습니다.

메일 건너뛰기

function my_skip_mail() {
    return true; // true skips sending the email
}
add_filter('wpcf7_skip_mail','my_skip_mail');

또는 추가skip_mail[ Additional Settings ]탭으로 이동합니다.

폼 ID 또는 투고 ID 취득

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {

    $post_id = $submission->get_meta('container_post_id');
    $form_id = $contact_form->id();

    // do something       

    return $contact_form;
    
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );

사용자 입력 데이터 가져오기

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {

    $your_name = $submission->get_posted_data('your-field-name');

    // do something       

    return $contact_form;
    
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );

동적 수신자에게 전자 메일 보내기

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {

    $dynamic_email = 'email@email.com'; // get your email address...

    $properties = $contact_form->get_properties();
    $properties['mail']['recipient'] = $dynamic_email;
    $contact_form->set_properties($properties);

    return $contact_form;
    
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );

덧붙이고 싶은 게 있는데, 그 이유는wpcf7_skip_mail필터:

add_filter( 'wpcf7_skip_mail', 'maybe_skip_mail', 10, 2 );

function maybe_skip_mail( $skip_mail, $contact_form ) {

    if( /* your condition */ )
        $skip_mail = true;

    return $skip_mail;

}

추가 설정에서 데모 모드를 켜면 이메일이 전송되지 않습니다.CF7 Docs에서 아래를 참조하십시오.

설정했을 경우demo_mode: on[ Additional Settings ]필드에서 연락처 폼이 데모모드가 됩니다.이 모드에서 연락처 양식은 메일 발송 프로세스를 건너뛰고 응답 메시지로 "완료됨"만 표시합니다.

언급URL : https://stackoverflow.com/questions/29926252/how-to-hook-into-contact-form-7-before-send

반응형