Contact Form 7 Change Action URL

To send form output to a different file put this in themes functions.php.

This code also limits this change to page 434 and adds the $wpcf7->skip_mail function to stop the form sending an email.

//change action url of contact form
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url($url)
global $post, $wpcf7;
if ($post->ID === 434) {
//its the payments page
// stop email being sent
$wpcf7->skip_mail = 1;
return '/wp-content/themes/mytheme/refresh.php';

} else {
return $url;

Form data is POSTed to refresh.php but the form ajax will keep the initial page loaded.

To redirect to the second file you can disable the Contact Form 7 scripts as described here

This removes validation but this can be added using a custom script as described here


  1. Konstantyn on May 30, 2013 at 11:17 pm

    You have a minor mistakes.

    1) // stop email being sent
    $wpcf7->skip_mail = 1;
    need write it before return and declare global $wpcf7.

    2) global $post;
    if ($post->ID === 434) {

    why page? use form id. it’s more flexible.

    global $wpcf7_contact_form;
    if ($wpcf7_contact_form->ID === your_form_id) {

    p.s. many thanks for your post

    • babbler on May 30, 2013 at 11:39 pm

      Thanks for your comments.
      The code as shown worked for me but in view of your comments I have edited my post to include your point 1).
      Your point 2) is good too but in my case I needed the page id to be the parameter. Same form, different pages, different actions.

      Thanks for your input

  2. Konstantyn on May 31, 2013 at 12:21 am

    Hmmmm.. I’ll checked $wpcf7 – this object doesn’t include ‘skip_mail’.

    Can you check. May be i make mistakes. Sorry

  3. barry on February 23, 2014 at 10:09 am


    I am trying your suggestion and in my case i point my WPCF7 form to /test/get.php and in get.php i just have print_r($_REQUEST);
    All this to test things, but now my form spinner keeps spinning and when i look in Network> resource

    [_wpcf7] => 159
    [_wpcf7_version] => 3.7.1
    [_wpcf7_locale] => en_US
    [_wpcf7_unit_tag] => wpcf7-f159-p162-o1
    [_wpnonce] => 270977c76b
    [your-name] => asdf
    [your-subject] => sd
    [your-message] => adsf
    [_wpcf7_is_ajax_call] => 1

    How can i make the response appear in place of the form and the spinner?

    Any tips, suggestions?

    ps: in the end it makes a call to a payment script (i hope)

    • babbler on February 23, 2014 at 12:35 pm

      My guess is that your form is being processed rather than redirecting to your script.
      There seems to be some uncertainty about whether:
      $wpcf7->skip_mail = 1;
      actually works (see the comment above comment from Konstantyn) as skip_mail appears not to be included in the $wpcf7 object any more.
      Try adding this to the Additional Settings before your redirection:
      demo_mode: on
      Let me know how you get on so I can correct the original post.

  4. Carlos on May 6, 2015 at 4:25 am

    hi this worked for me, It actually changes the actions but, in my site it shows a warning in the page what could be causing this?

    • babbler on May 12, 2015 at 1:58 pm

      Can you tell me what the warning says?

  5. luca on January 7, 2016 at 3:29 am

    I used in functions.php this code
    add_filter(‘wpcf7_form_action_url’, ‘wpcf7_custom_form_action_url’); function wpcf7_custom_form_action_url() { return ‘my external url’; }

    and I added in the additional settings of cf7 this code:
    add_filter(‘wpcf7_form_action_url’, ‘wpcf7_custom_form_action_url’);

    Now the form is correctly sending data to the external url but my problem is that after submission the form doesn’t show any messege and I don’t know to redirect to a thank you page. Do you have any idea how to do this?

    Thank you


  6. Chris on February 2, 2016 at 10:10 pm


    This worked for me, as I needed to pass the parameters to our CRM system. The CRM system will redirect to a URL after form submission but if I don’t disable the form 7 scripts, the initial page stays loaded and the icon keeps spinning.

    I really would like to keep the scripts intact for validation, but is there a way to keep the scripts loaded AND get to my redirected page?

    I’ve also tried adding my own custom scripts for form validation ,while it works, it’s not as slick as what form 7 has.

    Thank you!

Leave a Comment