This topic has 22 replies, 3 voices, and was last updated 5 years by Radu.

  • Author
  • #164316
     kjcarleo
    Participant

    Hello I am trying to do a rediect with the following code:

    <script>
    document.addEventListener( 'wpcf7mailsent', function( event ) {
        location = 'http://embassymarine.org/join-us-next=-steps';
    }, false );
    </script>
    The following article mentions (near the bottom) I should “Embed this snippet into your theme’s template file.“, what file would that be? And do I need the <script> handlers?
    The Article: https://contactform7.com/redirecting-to-another-url-after-submissions/
    Kevin
    #164387
     Laura
    Moderator

    Hello, will assign the ticket to a higher support level who can help and advise you in your query.
    Thanks! ?

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #164625
     Radu
    Moderator

    Hi,

    Just add it to wp-admin -> theme options -> general settings -> JavaScript code including the script tags
    That’s it

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #164641
     kjcarleo
    Participant

    I tried it with and without the <script> tags, but no redirect yet. Cleared the cache on the server and my internet cache as well. Any ideas?

    #164859
     Radu
    Moderator

    Hi,

    The Js snippet cannot be found in your source page

    Make sure you have added that…

    Paste the snippet again

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #164870
     kjcarleo
    Participant

    I see the snippet now, but it is still not working 🙁

    Attachments:
    You must be logged in to view attached files.
    #165029
     Radu
    Moderator

    I see there it’s an IF condition,

    Try to put the snippet as authr has provided as example

    COPY CODE
    
    <script>
    document.addEventListener( 'wpcf7mailsent', function( event ) {
        location = 'http://example.com/';
    }, false );
    </script>
    

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #165036
     kjcarleo
    Participant

    Yes, but I only want it to occur when this particular form is used, hence the “if” statement as referred at the bottom of this page:

    https://contactform7.com/dom-events/

    #165384
     Radu
    Moderator

    Hi,

    Just tested and it works,

    If you will add a form to a new page or existing one the alert it’s shown

    Inside the theme options JS I have this

    COPY CODE
    
    <script>
    
    jQuery(document).ready(function() {
    document.addEventListener( 'wpcf7submit', function( event ) {
        if ( '10032' == event.detail.contactFormId ) {
            alert( "The contact form ID is 10032." );
            // do something productive
        }
    }, false );
    });
    
    </script>
    
    
    

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #166795
     kjcarleo
    Participant

    That’s great, but what about making it redirect to another page, that code didn’t seem to work.

    #167027
     Radu
    Moderator

    Hi,

    That code will work only in pages where the contact form shortcode it’s placed like contact one, where the code doesn’t work?

    Are you want to use this in combo with floating contact from the kleo theme ? or how ?

    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #167542
     kjcarleo
    Participant

    I just want to use it on the following form: https://embassymarine.org/join-us/ [contact-form-7 id=”10326″ title=”Application for Membership”]

    I want it to redirect to another page after the form is submitted.

    Kevin

    #167816
     Radu
    Moderator

    Hi,

    Just add this code to JavaScript code from wp-admin -> theme options -> general options

    COPY CODE
    <script>
    
    jQuery(document).ready(function() {
    document.addEventListener( 'wpcf7submit', function( event ) {
        if ( '10032' == event.detail.contactFormId ) {
    window.location.href="http://google.com";
            // do something productive
        }
    }, false );
    });
    
    </script>

    Replace 10032 with the form id, it redirects after submit it works I’ve tested

    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #167910
     kjcarleo
    Participant

    I added the above code, but it is still not redirecting – please help.

    Here is the code I added to the Quick CSS Section under wp-admin -> theme options -> general options

    COPY CODE
    <script>
    
    jQuery(document).ready(function() {
    document.addEventListener( 'wpcf7submit', function( event ) {
        if ( '10326' == event.detail.contactFormId ) {
    window.location.href="https://embassymarine.org/join-us-next-steps/";
            // do something productive
        }
    }, false );
    });
    
    </script>
    #168068
     Radu
    Moderator

    Hi,

    That’s ODD, I don’t know what advice to give you at this moment, provide admin credentials.

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #168146
     kjcarleo
    Participant
    This reply has been set as private.
    #168427
     Radu
    Moderator

    Hi

    Let me know when the site it’s reachable

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #168454
     kjcarleo
    Participant

    You had to many sss’s https://embasssymarine.org

    https://embassymarine.org

    #168561
     Radu
    Moderator

    Hi,

    IT works, check : https://embassymarine.org/join-us/

    I’ve added the code in header content

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #216213
     kjcarleo
    Participant

    Guys I noticed it has been working this whole time, however even if there is an error on the form or filezise of attachment it still redirects and the form is never sent. Is there any way to only redirect if there are no errors?

    KJ

    #216258
     Radu
    Moderator

    Hi,

    For further development you will need to hire a dev to make the conditions in every case you need for your business.

    I recommend you to ask for a solution on contact form 7 forum since this question it’s more related to their product not ours.

    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #216261
     kjcarleo
    Participant

    0K

    #216296
     Radu
    Moderator

    Ok
    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 23 posts - 1 through 23 (of 23 total)

The forum ‘Bugs & Issues’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?