• I’m the author of CFDB which captures CF7 form submissions and saves them to the DB.

    The plugin listens to the wpcf7_before_send_mail hook and pulls the form submission data from the object passed in ($object->posted_data) but “posted_data” no longer appears. The passed in object does have the form definition information, but has none of the form submission data.

    Anyone else relying on wpcf7_before_send_mail to do something with with the data will also have this problem.

    Please advise on how data can be collected in version 3.9. Many sites are rely on both these plugins.

    Thank you.

Viewing 9 replies - 16 through 24 (of 24 total)
  • You can download and install the old 3.8 version from here:
    https://downloads.www.ads-software.com/plugin/contact-form-7.3.8.1.zip

    Make sure to have a complete backup before deleting the 3.9 and installing the old version. Than you should be able to restore the old form within minutes.

    Mmm Now I just have to figure out why WordPress is telling me that the contents of the zip file are empty.

    Rename the zip folder into contact-form-7.zip. Does this work? Maybe zip file has been corrupted due download?

    Thread Starter Michael Simpson

    (@msimpson)

    Some code that might help for backward compatibility:
    1. Take your old function hooked to wpcf7_before_send_mail, say it was called “hook”, and rename it to something else, say “hook1”
    2. Create a new version of “hook” that changes the data back to what it was before, then passes it to the original (now renamed) hook1:

    function hook() { // change to your function name
      $submission = WPCF7_Submission::get_instance();
      if ($submission) {
        $data = array();
        $data['title'] = $cf7->title();
        $data['posted_data'] = $submission->get_posted_data();
        $data['uploaded_files'] = $submission->uploaded_files();
        $obj = (object) $data;
        hook1($obj); // call the original function (now renamed)
      }
      return true;
    }
    Thread Starter Michael Simpson

    (@msimpson)

    @takayuki Mioyshi – minor thing:

    With regard to this code:

    $submission = WPCF7_Submission::get_instance();
    if ( $submission ) {
      $posted_data = $submission->get_posted_data();
    }

    Would you consider having get_posted_data() return a reference to the array? (or supply an additional method to do this)

    I have situations where users want to change the data that is submitted before it is saved. They do that using a “hook in my CFDB plugin but can also do this using your wpcf7_before_send_mail hook directly (see below).

    Prior to CF7 3.9, the hooks operated on a reference to the posted_data. Now they have a copy. For my purposes (changing some data before it is saved) it still works. But before CF7 3.9, when users modified the posted_data, they would see those changes in the email that CF7 sends out. Now they don’t.

    Here is my simplistic example. I have a form with a “name” field. I put in a simple hook for the purpose of upper-casing the name text submitted (calling ucfirst). I put in this hook:

    function cf7_ref_test() {
      $submission = WPCF7_Submission::get_instance();
      if ($submission) {
        // would like to get posted_data as a reference
        $data =& $submission->get_posted_data();
        if (isset($data['name'])) {
          $data['name'] = ucfirst($data['name']);
        }
      }
    }
    add_action('wpcf7_before_send_mail', 'cf7_ref_test');

    Although the hook is called, the email that I get from CF7 does not have the change because $submission->get_posted_data() returns a copy of the array.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    You can use wpcf7_posted_data filter for such purposes.

    Thread Starter Michael Simpson

    (@msimpson)

    I see. Unfortunately in that hook I only have posted_data, where users want to manipulate the title, posted_data, and uploaded_files just prior to saving & emailing. Users do things like conditionally map more than one form title into the same form title (to appear together in the DB) and grab the uploaded files and copy them somewhere, as well as adding & changing fields.

    To get all the benefits, they would have to register a function on wpcf7_posted_data to handle field changes that they want to see in email, then another on wpcf7_before_send_mail to handle title and uploaded files, which would not be reflected in emails. It’s awkward now.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Use the most appropriate hook for each purpose, please.

    I have the same question as Michael and can’t seem to follow along.

    I use “wpcf7_before_send_mail” to send the submitted form to a database. The database returns their unique key (insert_id). Then I would save that unique key back to the posted_data, but now posted_data is just a copy. Can’t figure out how to save it back to the original, so the email will capture it.

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘3.9 Breaks CFDB Plugin’ is closed to new replies.