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

时间:2017-03-15 10:59:44

标签: php wordpress contact-form-7

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

add_action( 'wpcf7_mail_sent', 'myfunction' );

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

我有一个这样的字段:[textarea your-message]

如何从中捕获POST数据?

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

5 个答案:

答案 0 :(得分: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'];


   }
}

答案 1 :(得分:3)

您需要访问$WPCF7_ContactForm对象。

在你的钩子函数中,你可以像这样访问你想要的字段:

yourFunction(&$WPCF7_ContactForm) {
    $text_area_contents = $WPCF7_ContactForm->posted_data['your-message'];
}

答案 2 :(得分:2)

在成功发送邮件后,这是我用来接收联系表格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']);

 }
}

答案 3 :(得分:0)

您可以通过 wpcf7_posted_data

检索表单字段数据
add_filter( 'wpcf7_posted_data', function( $data ) {
  echo $data['your-name'];
} );  

答案 4 :(得分:0)

尝试一下


add_action('wpcf7_before_send_mail','dynamic_addcc');
function dynamic_addcc($WPCF7_ContactForm){
    $currentformInstance  = WPCF7_ContactForm::get_current();
    $contactformsubmition = WPCF7_Submission::get_instance();
    if($contactformsubmition){
    $posted_data = $contactformsubmition->get_posted_data(); 
    }
}