Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture POST data with contact form7

I have this hook in my functions.php:

add_action( 'wpcf7_mail_sent', 'myfunction' );

I want to post the values when the form is sent.

I have a field like this: [textarea your-message].

How do i capture the POST data from this?

for example when the form is sent i want to echo the post value of [textarea your-message] in myfunction(){}

like image 904
Kevin.a Avatar asked Mar 15 '17 10:03

Kevin.a


People also ask

Does Contact Form 7 save to database?

Database for Contact Form 7 is a productivity add-on to save all form submissions into your database. Without this plugin, you have to check each and every email to manually copy and keep the data you want.

Where do Contact Form 7 Submissions go?

There's no additional setting up needed — the submissions you get through Contact Form 7 will be stored in the wp_posts database. If you want to see them, you can head over to the newly added Flamingo tab on your website's dashboard. There, you'll notice the “Address Book” and the “Inbound Messages” options.

How do I find contact form entries in WordPress?

WordPress plugin contact form database in wordpress go to “CRM Entries” menu then select your form, plugin will show all entries in table form.


2 Answers

This is how I used and its work for me to receive contact form 7 data after successe mail send and I used this data to send another server through 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']);

 }
}
like image 101
Shakil Hossain Avatar answered Sep 22 '22 00:09

Shakil Hossain


Try this :

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'];


   }
}
like image 36
Rakhi Prajapati Avatar answered Sep 21 '22 00:09

Rakhi Prajapati