A clean approach is to use the hook wpcf7_contact_form_properties
in a custom plugin, here is the plugin:
/*
Plugin Name: Multiple WPCF7's on_sent_ok
Plugin URI: http://kadimi.com/wpcf7-javascript-programmatically
Description: Use WPCF7's on_sent_ok many times.
Author: Nabil Kadimi
Version: 1.0
Author URI: http://kadimi.com/
*/
function se_21402617_wpcf7_properties( $properties, $contact_form_obj, $unused ){
$properties[ 'additional_settings' ] .=
"\n"
. 'on_sent_ok: "console.log(1);"' . "\n"
. 'on_sent_ok: "console.log(2);"' . "\n"
. 'on_sent_ok: "console.log(3);"' . "\n"
;
return $properties;
}
add_filter( 'wpcf7_contact_form_properties', 'se_21402617_wpcf7_properties' , 10, 2 );
As you can see in the plugin code, I used on_sent_ok
3 times.
You can filter which form is affected by inspecting the $contact_form_object
.
Source:
Code is derived from my blog post here.