Title: Custom function $posted_data not working after 5.2
Last modified: September 7, 2020

---

# Custom function $posted_data not working after 5.2

 *  [webmasterpcx](https://wordpress.org/support/users/webmasterpcx/)
 * (@webmasterpcx)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/custom-function-posted_data-not-working-after-5-2/)
 * Hi,
 * I have an issue since 5.2.1 update. 5.2.2 did not resolve my problem.
    I have
   a custom function to change recipient according to customer country or region.
   I was checking $submission->get_posted_data() to compare with my database to 
   find the right recipient email and change it before sending notification. Since
   5.2.1 update it doesn’t work anymore and I don’t know why because I don’t see
   anything related inside your changelog. I had to roll back to 5.2.
 * My function is hooked to wpcf7_before_send_mail and here is a piece of my function
   so you can see what I’m using inside :
 *     ```
       $current_mail_array = $contact_form->prop('mail');
       $submission = WPCF7_Submission::get_instance();
       $posted_data = $submission->get_posted_data();
       if(array_key_exists($posted_data['my_form_field'], $emailpays)) {
           $current_mail_array['recipient'] = $emailpays[$posted_data['my_form_field']];
         }
       $contact_form->set_properties(array('mail'=>$current_mail_array));
       ```
   
 * Do you know what my problem is and how can I solve it ?
    I would like to keep
   CF7 up to date.
 * Thanks,
    Have a nice day !

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

 *  [mstaudt](https://wordpress.org/support/users/mstaudt/)
 * (@mstaudt)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/custom-function-posted_data-not-working-after-5-2/#post-13370685)
 * Hi,
 * I have exactly the same problem.
 * Since cf7 v5.2.2 my own function to attach an xml-file created from form data
   doesn’t work anymore. My function is attached to the end of the file “settings.
   php” in the root of the cf7 plugin directory.
 * The form will not sent and the timer runs endlessly.
    The form works when I comment
   out: `$posted_data = $submission->get_posted_data();`
 * but then of course an xml without values will be attached.
    My code excerpt:
 *     ```
       <?php
       // define the callback function
       function my_get_form_values($contact_form) {
   
        // get info about the form and current submission instance
        $formTitle = $contact_form->title();
   
        // define which form you're looking for (if you have multiple) 
        if (($formTitle == "Objekt-Kauf-Suche") {
   
            $submission = WPCF7_Submission::get_instance();
            // get the actual data!
            if($submission) {
                $posted_data = $submission->get_posted_data();
            }
   
            // Get a serial number to distinguish report from others
            $serialNr = md5(uniqid(rand(), true));
   
            // Create xml doc spec
            $xmlDoc = new DOMDocument('1.0', 'ISO-8859-15');
            $xmlDoc->formatOutput = true;
   
            // Build XML file with root element
            $xmlRoot = $xmlDoc->createElement('openimmo_feedback');
            $xmlDoc->appendChild($xmlRoot);
   
   
            //node 'Interessent'
            $xml_Interessent = $xmlDoc->createElement('interessent');
   
            //nodes for 'Interessent'
   
            //first name
            $xml_vorname = $xmlDoc->createElement('vorname', $posted_data['vorname']);
            $xml_Interessent->appendChild($xml_vorname);
   
            //last name 
            $xml_nachname = $xmlDoc->createElement('nachname', $posted_data['nachname']);
            $xml_Interessent->appendChild($xml_nachname);
   
            //append interessent to objekt
            $xml_Objekt->appendChild($xml_Interessent);
   
            //append all to root
            $xmlRoot->appendChild($xml_Objekt);     
   
            //generate the path/filemame
            $file = "wp-content/plugins/contact-form-7/Kraus-Immo-".$formTitle."_".$serialNr.".xml";
   
            //generate the path/filemame for the temp. copy
            $file_copy = "wp-content/plugins/contact-form-7/Kraus-Immo-".$formTitle."_".$serialNr."_attach.xml";
   
            // save it as a file for further processing
            $content = chunk_split(base64_encode($xmlDoc->saveXML()));
            $xmlDoc->save($file);
   
            /* make temp. copy */
            copy($file, $file_copy );
   
            /* attach temp. copy */ 
            $submission->add_uploaded_file( 'xml', $file_copy); }
       }
   
       // add the action 
       add_action('wpcf7_before_send_mail', 'my_get_form_values', 10, 1);
       ```
   
 * Any help is very appreciatetd. Thanks in andvance!
 *  [mac33](https://wordpress.org/support/users/mac33/)
 * (@mac33)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/custom-function-posted_data-not-working-after-5-2/#post-13372971)
 * Hi,
    I have the same problem. Since cf7 v5.2.2 my own function to insert data
   in sellsy doesn’t work anymore. $posted_data = $submission->get_posted_data();
   How can I solve it ? Thanks, Have a nice day
 *  Thread Starter [webmasterpcx](https://wordpress.org/support/users/webmasterpcx/)
 * (@webmasterpcx)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/custom-function-posted_data-not-working-after-5-2/#post-13392366)
 * Well, we are at least 3 with the same issue, and I don’t think we are the only
   ones affected by it.
 * Do you know if you are going to resolve this in your next updates ?
 * I really don’t understand why get_posted_data() does not work anymore. If there
   is a new function, let us know with your developer docs.
 * Thanks a lot !
 *  [mac33](https://wordpress.org/support/users/mac33/)
 * (@mac33)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/custom-function-posted_data-not-working-after-5-2/#post-13408621)
 * I am in the same situation.
    Can you tell us if the next update will fix the 
   problem or if another function exists? Thank you so much !
 *     ```
         // Create the new wordpress action hook before sending the email from CF7
       add_action( 'wpcf7_before_send_mail', 'my_conversion' );
          function my_conversion( $contact_form ) {
          $submission = WPCF7_Submission::get_instance();
         $form_id = $contact_form->id();
         // Get the post data and other post meta values
       if ( $form_id == 1363 ) {
       if ( $submission ) {
           $posted_data = $submission->get_posted_data();
           $remote_ip = $submission->get_meta( 'remote_ip' );
           $url = $submission->get_meta( 'url' );
           $timestamp = gmdate("Y-m-d H:i:s", $submission->get_meta( 'timestamp' ));
           $title = wpcf7_special_mail_tag( '', '_post_title', '' );
       ```
   

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

The topic ‘Custom function $posted_data not working after 5.2’ 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/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [update](https://wordpress.org/support/topic-tag/update/)
 * [wpcf7_before_send_mail](https://wordpress.org/support/topic-tag/wpcf7_before_send_mail/)

 * 4 replies
 * 3 participants
 * Last reply from: [mac33](https://wordpress.org/support/users/mac33/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/custom-function-posted_data-not-working-after-5-2/#post-13408621)
 * Status: not resolved