如何使用联系人form7捕获POST数据

Kev*_*n.a 3 php wordpress contact-form-7

我在我的functions.php中有这个钩子:

add_action( 'wpcf7_mail_sent', 'myfunction' );
Run Code Online (Sandbox Code Playgroud)

我想在发送表单时发布值.

我有一个这样的领域:[textarea your-message].

如何从中捕获POST数据?

例如,当表单发送时,我想回显[textarea your-message]in 的post值 myfunction(){}

Rak*_*ati 5

试试这个 :

add_action( 'wpcf7_sent', 'your_wpcf7_function' ); 

function your_wpcf7_function( $contact_form ) {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();

if ( $submission ) {
    $posted_data = $submission->get_posted_data();
}
   if ( 'MyContactForm' == $title ) {

    $firstName = $posted_data['first-name'];
    $lastName = $posted_data['last-name'];


   }
}
Run Code Online (Sandbox Code Playgroud)


Sha*_*ain 5

这是我使用的方式,它的工作方式是在成功发送邮件后接收联系表单7数据,并使用此数据通过API发送另一台服务器

add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' ); 
function your_wpcf7_mail_sent_function( $contact_form ) {
    $title = $contact_form->title;
    $submission = WPCF7_Submission::get_instance();  
    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }       
   if ( 'Reagistation' == $title ) {
        $name = strtolower($posted_data['text-name']);
        $name = strtolower(str_replace(' ', '_',  $name));
        $email = strtolower($posted_data['email']);
        $phone = strtolower($posted_data['phone']);
        $Areyouarealtor = $posted_data['Areyouarealtor'];
        $ayor = strtolower($Areyouarealtor['0']);

 }
}
Run Code Online (Sandbox Code Playgroud)


yiv*_*ivi 3

You need to access the $WPCF7_ContactForm object.

In your hooked function, you'd access the field you want like this:

yourFunction(&$WPCF7_ContactForm) {
    $text_area_contents = $WPCF7_ContactForm->posted_data['your-message'];
}
Run Code Online (Sandbox Code Playgroud)