Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
941 views
in Technique[技术] by (71.8m points)

wordpress - Modify Contact Form 7 Submission Data

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 );
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...