To clarify, I am looking to pick up the “on_sent_ok” action outside of the plugin in my own functions file, so that I dont have to mod the plugin itself. Something like:
$('.wpcf7').onSentOk(function(data) { });
would be great!
I have the same requirement. Is there a way to do that? Thanks.
It’s not javascript but I found this link http://wordpress.org/support/topic/plugin-contact-form-7-php-after-form-submit?replies=11
Allows you to call a PHP function. Should do what you need.
That seems to be good enough for what I want to do 🙂 Not a problem that it isn’t Javascript, all I need is to add people’s details to an external newsletter system if they have ticked the box on the form, so a quick cURL should sort that out nicely 🙂
Thanks very much nagarsoft 🙂
How do you get it to redirect. I put this code in my functions.php file:
add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );
function your_wpcf7_mail_sent_function( $contact_form ) {
$title = $contact_form->title;
$posted_data = $contact_form->posted_data;
if ( $title == 'Newsletter Signup' ) {
$email = $posted_data['email'];
header('Location: http://campuzoic.us2.list-manage1.com/subscribe?u=e014c12069e8858be934de06e&id=e5c704e1b9&MERGE0=$email');
}
}
but it doesn’t redirect. What am I doing wrong? Please help! (And keep in mind that I know ZERO PHP, this is all just copy and paste. However, I am a programmer so I understand what is going on, I just don’t know the syntax)
The first thing I can see is:
header('Location: http://campuzoic.us2.list-manage1.com/subscribe?u=e014c12069e8858be934de06e&id=e5c704e1b9&MERGE0=$email');
At the end of that line where you have &MERGE0=$email
, the $email wont be evaluated, but will instead send exactly “$email” in the URL. To make it evaluate you will need to change ...04e1b9&MERGE0=$email');
with ...04e1b9&MERGE0='.$email);
Also, if it isn’t redirecting you could throw in some echo / error_log statements to make sure the code is executing and making it into the if statement.
Hope it helps 🙂
P.S. the reason it won’t be evaluated is because the line is wrapped in single quotes.
Anything in PHP wrapped in single quotes will be sent literally, anything in double quotes will evaluate variables, although it is still better practice (IMO) to break out of the quotes and concatenate the variable into the line e.g.
$random = "This is a random line with a " . $variable . " in it!";