Modify Contact Form 7 Submission Data

*爱你&永不变心* 提交于 2019-11-28 05:45:54

问题


I'm using Contact Form 7 on a site and need to alter the checkbox submitted data. The checkbox has a label called 'Tick here if you dont want to receive further marketing', when this is checked the value sent in the admins notification email displays the checkbox label. So it looks like:

Tick here if you dont want to receive further marketing: Tick here if you dont want to receive further marketing

I want to alter it so when its checked the value posted is No.

I believe I can use the following action hook to achieve this but I dont know how to check if the checkbox has been ticked within this function and modify its value.

Any help much appreciated.

// define the wpcf7_posted_data callback 
function action_wpcf7_posted_data( $array ) { 
// make action magic happen here... 
}; 

// add the action 
add_action( 'wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1 );

回答1:


I believe you can just use:

// define the wpcf7_posted_data callback 
function action_wpcf7_posted_data( $array ) { 
    //'checkbox-name' is the name that you gave the field in the CF7 admin.
    $value = $array['checkbox-name'];
    if( !empty( $value ) ){
        $array['checkbox-name'] = "New Value";
    }

    return $array;
}; 
add_filter( 'wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1 );


来源:https://stackoverflow.com/questions/40000543/modify-contact-form-7-submission-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!