• Resolved ethylsd

    (@ethylsd)


    Hello,

    Can you please help with our issue?

    Just noting that are using the latest version of Contact Form 7.

    Anyways, we have a custom code to send emails to different addresses depending on the selected enquiry type and role combine.

    We use the example code below to get specific data from the submission:

    $submission = WPCF7_Submission::get_instance();
    $data = $submission->get_posted_data();
    $full_name = $data['field_full_name'];

    This was previously working. However, for some reason, now the keys are incorrect and instead of the field names as keys, the values are now also the keys. And that breaks our code because $full_name = $data['field_full_name']; doesn’t work anymore.

    See the result of $data = $submission->get_posted_data();:
    http://files.swishdesign.com.au/gvKR2Ul

    We tried WPCF7_Submission::get_posted_data() but it is just returning 500 error on the console.

    The same goes with the $_POST, it also returning the same thing as the get_posted_data(), the key is the same as the value instead of the field name:
    http://files.swishdesign.com.au/9r5lDo8

    Can you please suggest any other way to get the submission data during the wpcf7_before_send_mail hook? Or if this is a bug, can you please look into it soon?

    I look forward to hearing back from you soon.

    Kind regards,
    Ethyl

    • This topic was modified 5 years, 8 months ago by ethylsd.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    Thread Starter ethylsd

    (@ethylsd)

    We don’t want to post it here but not sure if it’s possible to private a reply.

    The website is https://tesol.org.au/

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    What code do you use to output them to email messages? Where do you place the code and how do you trigger it?

    Thread Starter ethylsd

    (@ethylsd)

    We added the code on the functions.php file.

    We opt out the original code but below is a sample that reproduces the same issue:

    add_action( 'wpcf7_before_send_mail' , 'so_custom_before_send_mail', 999 );
    function so_custom_before_send_mail( $form ) {
    	$wpcf7 = WPCF7_ContactForm::get_current();
    	$submission = WPCF7_Submission::get_instance();
    
    	if ( $submission ) {
    		$data = $submission->get_posted_data();
    		$mail = $wpcf7->prop('mail');
    
    		$mail['body'] .= "\n";
    		$mail['body'] .= "\n" . print_r( $data, true );
    		$mail['body'] .= "\n" . print_r( $_POST, true );
    
    		$wpcf7->set_properties(array(
    			'mail' => $mail
    		));
    
    		return $wpcf7;
    	}
    }

    It’s just printing the form data but it’s still producing the same issue.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    It’s just that keys in the array are treated as mail-tags.

    First, print_r() outputs like this:

    Array
    (
    [FNAME] => Full Name
    [EMAIL] => [email protected]
    [Phone] => 00000000
    ...

    And then, Contact Form 7 replaces mail-tags:

    Array
    (
    Full Name => Full Name
    [email protected] => [email protected]
    00000000 => 00000000
    ...
    Thread Starter ethylsd

    (@ethylsd)

    Of course, it will convert them! Thank you for clarifying that.

    However, get_posted_data() doesn’t work from our end but $_POST does. We’re quite confused about this as we never did any changes to our codes before.

    In the meantime, this resolved our issue by using $_POST.

    Thanks!

    Plugin Author Takayuki Miyoshi

    (@takayukister)

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

The topic ‘Issue with get_posted_data() or $_POST keys’ is closed to new replies.