how to change form action url for contact form 7?

后端 未结 4 1237
南笙
南笙 2020-12-14 04:17

I\'m using Contact Form 7 in a wordpress site with multiple forms. I need to direct one form to a different form action url than the others.

I found the reply below

4条回答
  •  不知归路
    2020-12-14 05:15

    Great answer @maiorano84 but I think you should check form ID instead of Post. Here is my version.

    add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
    function wpcf7_custom_form_action_url($url)
    {
        $wpcf7 = WPCF7_ContactForm::get_current();
        $wpcf7_id = $wpcf7->id();
    
        $form_id = 123;
        
    
        return $wpcf7_id == $form_id? '/action.php' : $url;
    }
    

    Another thing you might need to disable WPCF7 AJAX. That can be disabled by placing the following code in your wp-config.php

    define('WPCF7_LOAD_JS', false);
    

提交回复
热议问题