• How to get the ‘addEventListener’ to work with different forms
    am looking to have a different ‘thank you’ page for 3 forms i am using ?

    document.addEventListener( 'wpcf7mailsent', function( event ) {
        location = 'https://example.com/';
    }, false )
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    See https://contactform7.com/2017/06/07/on-sent-ok-is-deprecated/

    There is an example code at the bottom that shows how to do conditional branching based on the contact form ID.

    Thread Starter dmorton2

    (@dmorton2)

    @takayukister thanks

    To do multiple forms then, it would look like this then ?

    if (condition1)
       statement1
    else
       if (condition2)
          statement2
       else
          if (condition3)
      }
    }
    
    Thread Starter dmorton2

    (@dmorton2)

    Tired doing like below but didnt work ??

    	
    document.addEventListener( 'wpcf7mailsent', function( event ) {
        if ( 'wpcf7-f42-p437-o1' == event.detail.contactFormId ) { //HOME survey
            location = 'https://www.ptp.com/thank-you-survey/';
        } else if ( 'wpcf7-f31-p437-o2' == event.detail.contactFormId ) { //HOME newsletter
    		location = 'https://www.ptp.com/thank-you-for-signing-up/';
    	} else if ( 'wpcf7-f42-p11-o1' == event.detail.contactFormId ) { //ABOUT survey
            location = 'https://www.ptp.com/thank-you-survey/';
        } else if ( 'wpcf7-f42-p11-o2' == event.detail.contactFormId ) { //ABOUT newsletter
    		location = 'https://www.ptp.com/thank-you-for-signing-up/';
    	} else if ( 'wpcf7-f42-p13-o1' == event.detail.contactFormId ) { //PRODUCT survey
            location = 'https://www.ptp.com/thank-you-survey/';
        } else if ( 'wpcf7-f42-p13-o2' == event.detail.contactFormId ) { //PRODUCT newsletter
    		location = 'https://www.ptp.com/thank-you-for-signing-up/';
    	} else if ( 'wpcf7-f31-p15-o1' == event.detail.contactFormId ) { //HS survey
            location = 'https://www.ptp.com/thank-you-survey/';
        } else if ( 'wpcf7-f31-p15-o2' == event.detail.contactFormId ) { //HS newsletter
    		location = 'https://www.ptp.com/thank-you-for-signing-up/';
    	} else if ( 'wpcf7-f6-p21-o1' == event.detail.contactFormId ) { //CONTACT FORM
            location = 'https://www.ptp.com/thank-you/';
        } else if ( 'wpcf7-f6-p21-o2' == event.detail.contactFormId ) { //CONTACT newsletter
    		location = 'https://www.ptp.com/thank-you-for-signing-up/';
    	}	
    	
    }, false );	
    	
    anonymized-15380454

    (@anonymized-15380454)

    event.detail.contactFormId is the form ID saved in the database, and not the HTML ID of the form on the page.

    You can find the ID from the generated Shortcode. E.g.

    [contact-form-7 id="5" title="Contact form 1"]

    In the above example, the form ID is 5.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘thank you page for different forms’ is closed to new replies.