wordpress 更新联系表单FormData

5uzkadbs  于 4个月前  发布在  WordPress
关注(0)|答案(1)|浏览(57)

您好,我正在使用以下代码更改Contact Form 7的表单数据值:
我想更新这个值,我该怎么做?
您好,我正在使用以下代码更改Contact Form 7的表单数据值:

add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");

function wpcf7_do_something_else($cf7) {

$wpcf = WPCF7_ContactForm::get_current();

// get form data
$submission = WPCF7_Submission::get_instance();

if ($submission) {
    // get submitted data
    $posted_data = $submission->get_posted_data()['phone-271'];
    $submission->get_posted_data()['phone-271'] = "456464646";

    // Output the form data to the browser console
    // echo '\<script\>console.log(' . $posted_data . ')\</script\>';
}

return $wpcf;

字符串
}
我想更新这个值,我该怎么做?`

xa9qqrwz

xa9qqrwz1#

这里是代码,你怎么能实现

add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");

function wpcf7_do_something_else($cf7) {
    $submission = WPCF7_Submission::get_instance();

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

        
        if (isset($posted_data['phone-271'])) {
            
            $posted_data['phone-271'] = "456464646";

            // Optional: Output the original form data to the browser console
            // echo '<script>console.log(' . json_encode($posted_data) . ')</script>';
        }
    }

    return $cf7;
}

字符串

相关问题