1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[guide] URL Parameters in Contact Form 7

Discussion in 'Blogging' started by Conor, Sep 3, 2014.

  1. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,373
    Likes Received:
    5,439
    Gender:
    Male
    Location:
    South Africa
    Home Page:
    I spent the whole morning researching this, so I thought I may as well share:

    Note: This code doesn't populate your contact form using URL parameters. Instead, it grabs the data from any fields you like, and adds them to a redirect URL. It's is great if you'd like to create a custom "Thank You" page, or something similar.

    Add this code somewhere on the page, preferably in the footer, or just below your form's shortcode:
    Code:
    <script>
        function my_redirect() {
            var name = document.getElementById('your-name').value;
            var email = document.getElementById('your-email').value;
            var url = 'http://example.com/thank-you?name='+name+'&email='+email+'';
            window.location = url;
        }
    </script>
    
    Add this to the "Additional Settings" box in Contact Form 7:
    Code:
    on_sent_ok: 'my_redirect();'
    
    Make sure the ID's of the form fields match those in the first bit of code (your-name, your-email, etc).

    You could easily implement this to other contact forms if you don't use CF7. I'll do my best to answer any questions.

    Enjoy!
     
    • Thanks Thanks x 2
  2. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,373
    Likes Received:
    5,439
    Gender:
    Male
    Location:
    South Africa
    Home Page: