0
votes

Wordpress with Template form 7.

I've got pages 1,2,3 with links to the feedback page feedback:

  1. site.com/page1/ with URL = a href = "site.com/feedback?type=1"
  2. site.com/page2/ with URL = a href = "site.com/feedback?type=2"
  3. site.com/page3/ with URL = a href = "site.com/feedback?type=3"

I want to show special layout of Contact Form 7 depend on variable value (type 1, type 2, type 3)

This plugin Contact Form 7 Dynamic Text Extension (link here) can read var value, But I can't switch special Contact Form 7 block according to var value. :-(

I found this plugin - Contact Form 7 - Conditional Fields (but it create fields for one forms). But I need to show on page 3 "ready to insert" templates:-(

is it possible to show Contact Form 7 id shortcode depend on site.com/feedback?type=(number)?

Thanks in advance for advices.

1

1 Answers

1
votes

You can create a custom shortcode to call contact form 7 that uses the $_GET parameter from the URL. You'll have to place this function in your functions.php of your child theme or theme. Replace the contact-form-7 id's with the ones you're using. Also... you can keep going and put as many as you want. You could also use a php switch instead of if elseif, etc.

So on your page template, don't use the [contact-form-7] shortcode, instead just put [my-cf7]

add_shortcode('my-cf7', 'so_61464677_cf7_shortcode');
function so_61464677_cf7_shortcode(){
    if ($_GET['type'] == 2){
        return do_shortcode('[contact-form-7 id="2"]');
    } elseif ($_GET['type'] == 3) {
        return do_shortcode('[contact-form-7 id="3"]');
    } else {
        return do_shortcode('[contact-form-7 id="1"]');
    }
}