How to prevent redirect to a certain URL after submission of Contact Form 7 without input required fields












2















My goal is to redirect to an external URL after submission of the Contact Form 7 but only if all required fields are filled in. Instead of this I get a redirect every time, even if all fields are blank.
Fields without input are being marked as invalid but it is not preventing redirection.



<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" onclick="window.location.href='https://example.com'" />










share|improve this question























  • you can define a function on click to check whether all fields are filled properly. then you may redirect.

    – Ashish
    Jan 3 at 12:55











  • Thank you Ashish. Do you have any idea how to create this function?

    – Yuri
    Jan 3 at 13:30
















2















My goal is to redirect to an external URL after submission of the Contact Form 7 but only if all required fields are filled in. Instead of this I get a redirect every time, even if all fields are blank.
Fields without input are being marked as invalid but it is not preventing redirection.



<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" onclick="window.location.href='https://example.com'" />










share|improve this question























  • you can define a function on click to check whether all fields are filled properly. then you may redirect.

    – Ashish
    Jan 3 at 12:55











  • Thank you Ashish. Do you have any idea how to create this function?

    – Yuri
    Jan 3 at 13:30














2












2








2








My goal is to redirect to an external URL after submission of the Contact Form 7 but only if all required fields are filled in. Instead of this I get a redirect every time, even if all fields are blank.
Fields without input are being marked as invalid but it is not preventing redirection.



<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" onclick="window.location.href='https://example.com'" />










share|improve this question














My goal is to redirect to an external URL after submission of the Contact Form 7 but only if all required fields are filled in. Instead of this I get a redirect every time, even if all fields are blank.
Fields without input are being marked as invalid but it is not preventing redirection.



<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" onclick="window.location.href='https://example.com'" />







javascript html wordpress contact-form-7






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 12:49









YuriYuri

207




207













  • you can define a function on click to check whether all fields are filled properly. then you may redirect.

    – Ashish
    Jan 3 at 12:55











  • Thank you Ashish. Do you have any idea how to create this function?

    – Yuri
    Jan 3 at 13:30



















  • you can define a function on click to check whether all fields are filled properly. then you may redirect.

    – Ashish
    Jan 3 at 12:55











  • Thank you Ashish. Do you have any idea how to create this function?

    – Yuri
    Jan 3 at 13:30

















you can define a function on click to check whether all fields are filled properly. then you may redirect.

– Ashish
Jan 3 at 12:55





you can define a function on click to check whether all fields are filled properly. then you may redirect.

– Ashish
Jan 3 at 12:55













Thank you Ashish. Do you have any idea how to create this function?

– Yuri
Jan 3 at 13:30





Thank you Ashish. Do you have any idea how to create this function?

– Yuri
Jan 3 at 13:30












1 Answer
1






active

oldest

votes


















0














There are some events which will help you to achieve your scenario. In your case event should be called once email sent so you can use wpcf7mailsent for this.



At the footer add following code.



  <script type="text/javascript">

document.addEventListener( 'wpcf7mailsent', function( event ) {
window.location.href='https://example.com'
}, false );
</script>





share|improve this answer
























  • Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

    – Yuri
    Jan 3 at 13:28











  • Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

    – dipmala
    Jan 3 at 13:54












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022647%2fhow-to-prevent-redirect-to-a-certain-url-after-submission-of-contact-form-7-with%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There are some events which will help you to achieve your scenario. In your case event should be called once email sent so you can use wpcf7mailsent for this.



At the footer add following code.



  <script type="text/javascript">

document.addEventListener( 'wpcf7mailsent', function( event ) {
window.location.href='https://example.com'
}, false );
</script>





share|improve this answer
























  • Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

    – Yuri
    Jan 3 at 13:28











  • Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

    – dipmala
    Jan 3 at 13:54
















0














There are some events which will help you to achieve your scenario. In your case event should be called once email sent so you can use wpcf7mailsent for this.



At the footer add following code.



  <script type="text/javascript">

document.addEventListener( 'wpcf7mailsent', function( event ) {
window.location.href='https://example.com'
}, false );
</script>





share|improve this answer
























  • Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

    – Yuri
    Jan 3 at 13:28











  • Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

    – dipmala
    Jan 3 at 13:54














0












0








0







There are some events which will help you to achieve your scenario. In your case event should be called once email sent so you can use wpcf7mailsent for this.



At the footer add following code.



  <script type="text/javascript">

document.addEventListener( 'wpcf7mailsent', function( event ) {
window.location.href='https://example.com'
}, false );
</script>





share|improve this answer













There are some events which will help you to achieve your scenario. In your case event should be called once email sent so you can use wpcf7mailsent for this.



At the footer add following code.



  <script type="text/javascript">

document.addEventListener( 'wpcf7mailsent', function( event ) {
window.location.href='https://example.com'
}, false );
</script>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 13:03









dipmaladipmala

1,64411217




1,64411217













  • Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

    – Yuri
    Jan 3 at 13:28











  • Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

    – dipmala
    Jan 3 at 13:54



















  • Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

    – Yuri
    Jan 3 at 13:28











  • Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

    – dipmala
    Jan 3 at 13:54

















Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

– Yuri
Jan 3 at 13:28





Thank you Dipmala. I tried to use DOM event but there is a one feature in my project. I use conditional fields which open certain Submit buttons when certain condition is chosen and each submit button has its own redirect page. I tried to add ID-s to each Submit button to identify them: document.addEventListener( 'wpcf7submit', function( event ) { if ( 'submitbutton_id' == event.detail.contactFormId ) { location = 'http://example.com/'; } }, false ); But problem is that event.detail.contactFormId is the ID of the whole contact form, not the current Submit button only.

– Yuri
Jan 3 at 13:28













Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

– dipmala
Jan 3 at 13:54





Then you can check in this way when you add the condition also some fields are there and its value will be added so add the condition for that field. and add redirection based on that.

– dipmala
Jan 3 at 13:54




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022647%2fhow-to-prevent-redirect-to-a-certain-url-after-submission-of-contact-form-7-with%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas