I've been attempting to change CF7 form fields dynamically without using Contact Form 7 Dynamic Text Extension. I've seen a ton of articles on how to get posted data, just not on how I can overwrite existing values. My goal is to dynamically change the file attachment and add other meta-data associated with each post. Can this be done? Thank you!
Here's what I have so far:
function wpcf7_custom_before_send(&$cf7) {
if ( $cf7->id == 4 ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$data =& $submission->get_posted_data();
// how do I overwrite posted data?
}
}
}
add_action("wpcf7_before_send_mail", "wpcf7_custom_before_send");
You can use my code to do this. Some explanations for your code:
1) Since id
$cf7->id
property is no longer accessible. Use id() method instead$cf7->id()
.2) No need use
&
for callback$cf7
and$submission
. Use for thisreturn
.That is all, we are changed some tags, and send email with modified tag ;-)