Title: [Plugin: Contact Form 7] Database entry with form send
Last modified: August 19, 2016

---

# [Plugin: Contact Form 7] Database entry with form send

 *  Resolved [WiSch](https://wordpress.org/support/users/wisch/)
 * (@wisch)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-database-entry-with-form-send/)
 * Hello.
 * Is it possible to start a own little (PHP) Script with every mail wich is sent
   from contact form 7?
 * I want the user to subscribe for an event via contactform and with that a counter
   for the total subscribers should be updated.
 * Sorry for my english, hope somebody understands an can help me.
 * Thanks.
 * [http://wordpress.org/extend/plugins/contact-form-7/](http://wordpress.org/extend/plugins/contact-form-7/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [WiSch](https://wordpress.org/support/users/wisch/)
 * (@wisch)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-database-entry-with-form-send/#post-1736337)
 * Hello.
 * I found out, that I can use a so called Hook to realize that…
    I tried the following
   code in my functions.php but it didn’t work. The form ist send via Mail but the
   Meta-field did not change the value… Did someone see the error?
 * Thanks for your help.
 *     ```
       function wpcf7_vor_mailversand($cf7) {
         $current_post_id = $post->ID;
         $anmeldungen = get_post_meta($current_post_id, 'Anmeldungen', true);
         $anmeldungen++;
         update_post_meta($current_post_id, 'Anmeldungen', $anmeldungen);
       }
       add_action( 'wpcf7_before_send_mail', 'wpcf7_vor_mailversand' );
       ```
   
 *  Thread Starter [WiSch](https://wordpress.org/support/users/wisch/)
 * (@wisch)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-database-entry-with-form-send/#post-1736338)
 * Hello again.
 * It seems that the above code is not the problem because if I try this
 *     ```
       function mycf7_vor_mailversand($cf7) {
           $current_postid = 1952;
           $anmeldungen = '33';
           update_post_meta($current_postid, 'Anmeldungen', $anmeldungen);
       }
       add_action( 'wpcf7_before_send_mail', 'mycf7_vor_mailversand' );
       ```
   
 * it didn’t work either!?
 * Someone out there?
 *  Thread Starter [WiSch](https://wordpress.org/support/users/wisch/)
 * (@wisch)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-database-entry-with-form-send/#post-1736339)
 * Nobody can help?
 * Now the following code works to increment my custom field.
    But as you can see,
   it uses a fixed Post-ID… everything I try to get the Post-ID from the actual 
   post where the form is built in failed.
 *     ```
       function mycf7_vor_mailversand($cf7) {
           global $post;
           $current_postid = 1952;
           //$current_postid = $cf7->posted_data["_post_id"];
           //$current_postid = $_POST['post_ID'];
           //$current_postid = ($post->ID);
           $anmeldungen = get_post_meta($current_postid, 'Anmeldungen', true);
           $anmeldungen++;
           update_post_meta($current_postid, 'Anmeldungen', $anmeldungen);
       }
       add_action( 'wpcf7_before_send_mail', 'mycf7_vor_mailversand' );
       ```
   
 * As you can see, I even try to pass the post-id as a field from CF7.
    I also tried“
   global $wpdb;” or “global $_post;” instead of “global $post;” because I found
   somebody here in the forum that someone uses it that way…
 * Also tried a $anmeldungen = get_post_meta($post->ID, ‘Anmeldungen’, true); without
   succsess.
 * So at last: How can a get the Post-ID of the actual post from where the form 
   sends?
 * Thanks for your help.
 *  Thread Starter [WiSch](https://wordpress.org/support/users/wisch/)
 * (@wisch)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-database-entry-with-form-send/#post-1736340)
 * I found a solution that works for me:
 *     ```
       function mycf7_before_send_mail($cf7) {
       // Execute this Code only for Form-ID 3!
       if ( 3 == $cf7->id ) {
       $my_postid = wpcf7_special_mail_tag_for_post_data( $output, ‘_post_id’ ) ;
   
       }
       }
       add_action( ‘wpcf7_before_send_mail’, ‘mycf7_before_send_mail’ );
       ```
   
 * [This helped me.](http://www.ceata.org/proiecte/strajer/depozit/revisions/357/entry/Observator/observator-src/wp-content/plugins/contact-form-7/modules/special-mail-tags.php)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: Contact Form 7] Database entry with form send’ is closed to 
new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 4 replies
 * 1 participant
 * Last reply from: [WiSch](https://wordpress.org/support/users/wisch/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-database-entry-with-form-send/#post-1736340)
 * Status: resolved