rename name in contact from 7 before submit

30 Views Asked by At

Im trying to rename name of input in contact from 7. There is integration with google sheets, and name of input must be same as is named a column in the sheet. Issue is when you need two words name, its not supported.

Here is code what should rename input:


function custom_rename_form_field($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $data = $submission->get_posted_data();
        
        if (isset($data['jaky-obchod'])) {
            $jakyObchodValue = $data['jaky-obchod'];
            
            unset($data['jaky-obchod']);
            
            $data['Jaký obchod'] = $jakyObchodValue;
            
            $submission->set_posted_data($data);
        }
    }
}

But im getting error 500.

name "jaky-obchod" should be renamed to "Jaký obchod" before contact from 7 send data

1

There are 1 best solutions below

1
Ozmen Celik On

What about this ? Try wpcf7_before_send_mail hook instead of wpcf7_submit...

add_action('wpcf7_before_send_mail', 'custom_rename_form_field');

function custom_rename_form_field($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $data = $submission->get_posted_data();
        
        if (isset($data['jaky-obchod'])) {
            $jakyObchodValue = $data['jaky-obchod'];
            
            unset($data['jaky-obchod']);
            
            $data['Jaký_obchod'] = $jakyObchodValue;
            
            $submission->set_posted_data($data);
        }
    }
}