PeterCoon
PeterCoon

Reputation: 21

Custom action after submit Contact Form 7

I am using Contact Form 7 on Wordpress and I need put the scripts after the Submit button is clicked - and I really have no idea how to do it right. Can you please tell me easy way to implement it?

The codes are - one iframe url and the other is javascript code.

Upvotes: 2

Views: 20252

Answers (2)

a1i3n
a1i3n

Reputation: 5

Go to 'Contact Form 7' plugin directory then open 'contact-form.php' file located in 'includes' folder. Find line with 'action' string and change value to your response.

  'action' => esc_url( $url ) // should be original line
  'action' => 'send.php' // i guess it what you need

Upvotes: -2

Jasbir
Jasbir

Reputation: 376

Contact Form 7 has a wpcf7_mail_sent hook for exactly this. Usage looks a little like:

// ...in functions.php
add_action('wpcf7_mail_sent', function ($cf7) {
    // Run code after the email has been sent
});

There is also wpcf7_mail_failed, which lets you hook into when the email fails.

Or

on_sent_ok: "ga( 'send', 'event', 'Contact Form', 'submit' );"

You should replace it with:

document.addEventListener( 'wpcf7mailsent', function( event ) {
    ga( 'send', 'event', 'Contact Form', 'submit' );
}, false );

The JavaScript code can be placed e.g. in the footer of your page.

Upvotes: 5

Related Questions