how to change form action url for contact form 7?

后端 未结 4 1236
南笙
南笙 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 04:49

    According to @abbas-arif, his solution works great, but have a limitation. This solution change the form's action on all forms present in post with that ID. A better solution should be to use directly the form's ID. To get it, whit wordpress >5.2, you can use:

    add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
    function wpcf7_custom_form_action_url($url)
    {
        $cf7forms = WPCF7_ContactForm::get_current();
        $Form = $cf7forms -> id;
        
        
            switch($Form){
                case 1:
                    return 'destination like salesforce url 1...';
                case 2:
                    return 'destination like salesforce url 2...';
                case 3:
                    return 'destination like salesforce url 3...';
                default:
                    return $url;
                
            }
    
    }
    

提交回复
热议问题