Support » Plugin: Contact Form 7 » Critical issue with 5.2

  • Yuval


    Hi @takayukister,

    There is a bug on 5.2v.

    function wpcf7_dynamic_recipient( $wpcf7 ) {
    	$submission = WPCF7_Submission::get_instance();
    	$posted_data = $submission->get_posted_data();
    	print_r( $posted_data );
    add_action( 'wpcf7_before_send_mail', 'wpcf7_dynamic_recipient' );

    $posted_data[‘_wpcf7_container_post’] is missing. Also, all the other hidden fields are missing.


Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Takayuki Miyoshi


    Not a bug. That is the correct behavior.

    Thread Starter Yuval


    Hi @takayukister,

    Thank you for replying.

    In all previous versions we’ve used there was a $posted_data[‘_wpcf7_container_post’] key. We have used to it to alter the recipient in dozens of websites.
    Now, it’s not working anymore. We have to use older version of the plugin, or change the code in over 200 websites.

    Why would you change that?
    What about backward compatibility?

    This is most definitely a bug – whether or not you consider this correct behavior now, the fact this change was not marked in the changelog and I had to go through and debug the input coming through to find the field just didn’t exist in the data anymore is nonsense.

    My plugin is dependent on the _wpcf7 hidden field coming through so I know what form ID is being passed. That’s gone now. Why was this removed?

    @takayukister – We’re encountering the same problem. We were using the $form_data['_wpcf7'] variable in wpcf7_before_send_mail to know which contact form was calling the hook.

    What’s the proper replacement for that? Our custom form function has apparently been silently broken for the last two weeks due to the backwards incompatible change.


    We were able to replace this code:

    $submission = WPCF7_Submission::get_instance();
    $form_data = $submission -> get_posted_data();
    $contact_form_id = $form_data['_wpcf7'];

    with this code:

    $contact_form = WPCF7_ContactForm::get_current();
    $contact_form_id = $contact_form -> id;

    I assume that that’s the more proper way to do it, but it would have been better if they had left it alone for the sake of backwards compatibility.

    • This reply was modified 1 year, 2 months ago by pikamander2.
    • This reply was modified 1 year, 2 months ago by pikamander2.

    I also spent couple of hours fixing issues after update. No info or warning in changelog, no explanation, no backwards compatibility. Did you lost your mind? 🙁


    Seems I encounter problems due to the same change, “breaking my head” looking for the source.

    I have the below code that may need to be fixed:

    function generate_pdf($contact_form) {


    $submission = WPCF7_Submission::get_instance();
    if ($submission && !empty($_COOKIE[IDENTIFY_USER_COOKIE])) {

    $posted_data = $submission->get_posted_data();

    $uploadDir = wp_get_upload_dir();

    if (!empty($posted_data[‘_wpcf7’]) && $posted_data[‘_wpcf7’] == 2816) {….

    I’ll be happy to hear what you (@takayukister) advise as a solution.



    same (huge) problem for me too…have so many customers with functions appending on the
    $submission = WPCF7_Submission::get_instance();
    $posted_data = $submission->get_posted_data();

    Please Takayuki Miyoshi provide at least an alternative solution.



    Hi, @pikamander2

    Thank you, I’ve been able to successfully retrieve my form’s id.
    I’m still retrieving the recaptcha response through:

    $submission = WPCF7_Submission::get_instance();
    $form_data = $submission -> get_posted_data();

    But how do I get:

    With this instead:



    Note the answer I got:
    See Accessing user input data

    Recommended way to retrieve contact form ID:

    $submission = WPCF7_Submission::get_instance();
    $contact_form = $submission->get_contact_form();
    $contact_form_id = $contact_form->id();

    And reference to article:

    Accessing user input data

    To access user input posted through a contact form, you can refer to PHP’s native global variable $_POST. Besides this, Contact Form 7’s WPCF7_Submission class provides a different data source ($posted_data) that can be used to access user input. What are the differences between $_POST and $posted_data? And which one should you use for your purpose?

    $_POST includes raw data that the user has posted. $posted_data includes data that are sanitized and processed for use by Contact Form 7.

    While $_POST includes all posted data, some that represent meta information of the submission (such as the ID of the contact form) and some that are irrelevant to the submitter’s intention (such as the answer to a CAPTCHA question) are excluded from $posted_data.

    The following code snippet shows an example that retrieves user input from $posted_data.

    add_action( ‘wpcf7_before_send_mail’,
    function( $contact_form, $abort, $submission ) {
    // Getting user input through the your-email field
    $your_email = $submission->get_posted_data( ‘your-email’ );

    // Getting user input through the your-message field
    $your_message = $submission->get_posted_data( ‘your-message’ );

    // Do some productive things here
    10, 3
    As you see in this example, you use the get_posted_data() method to access the data. You are not allowed to directly access the $posted_data property.

    Don’t use $posted_data for validation or spam-filtering.
    Don’t use $posted_data for input validation or spam-filtering. Use $_POST instead, because those tasks make sense only when done against raw user input data

    • This reply was modified 1 year ago by ziegel.


    Please also see a NEW ticket I have just opened on:

    This change-log may be related to the issue:

    See also an answer on:

    Yes, the posted data array doesn’t include _wpcf7, and this is the correct behavior. If you want to know the ID of a contact form then use

    $id = $submission->get_contact_form()->id();

    • This reply was modified 1 year ago by ziegel.
    • This reply was modified 1 year ago by ziegel.


    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
    $posted_data = $submission->get_posted_data();

    need quick solution. thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Critical issue with 5.2’ is closed to new replies.