How to Customize What Happens After a Contact Form 7 Submission
Content
One of the most common questions from Contact Form 7 users is how to control what happens after a visitor clicks the submit button. Many users want to go beyond the default behavior of displaying a success message on the same page. Common requests include hiding the form, redirecting to a thank you page, triggering a print dialog, or displaying a large, custom success message.
This guide explains why this customization is needed and provides the most common solutions based on community knowledge.
Why Contact Form 7 Behaves This Way
By design, Contact Form 7 is a lightweight form handler. Its core functionality is to process form submissions via AJAX and then display a response message (like 'Your message was sent successfully') within the wpcf7-response-output div, which is located inside the form itself. This simple approach works for most basic use cases but lacks built-in options for more advanced post-submission actions, which is why users often seek customization.
Common Solutions for Customizing Post-Submission Actions
1. Redirecting to a Thank You Page
This is a highly requested feature. To redirect a user to another URL after a successful submission, you can use the wpcf7mailsent DOM event. This JavaScript event fires when the mail is successfully sent.
How to implement it:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '123' === event.detail.contactFormId ) { // Replace 123 with your form's ID
location = 'https://yourwebsite.com/thank-you/';
}
}, false );
</script>
You will need to add this code to your theme's footer or using a plugin that allows you to insert header/footer scripts. Remember to replace 123 with your actual form ID and the URL with your thank you page.
2. Hiding the Form After Submission
If you want to stay on the same page but hide the form, leaving only the success message visible, you can also use JavaScript.
Example code:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
// Hide the form
document.querySelector('.wpcf7-form').style.display = 'none';
// Optionally, you can also style the success message to make it bigger
document.querySelector('.wpcf7-response-output').style.fontSize = '2em';
}, false );
</script>
3. Triggering a Custom Action (Like window.print())
As mentioned in the sample threads, some users want to trigger a print dialog without leaving the page. The wpcf7mailsent event is perfect for this.
Example code to open a print dialog:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
window.print();
}, false );
</script>
4. Using a Thank You Page Redirect Plugin
For users who are not comfortable adding code, several third-party plugins can add redirect functionality through a simple settings interface. Searching the WordPress plugin repository for "contact form 7 redirect" will yield several options.
Important Considerations
- Form ID: Always check and use the correct Contact Form 7 ID in your JavaScript conditions to ensure your code only affects the intended form.
- Testing: Thoroughly test any custom code on a staging site before deploying it to your live website.
- HTML in Messages: Note that HTML, including links (
<a href>), is not allowed in the default success messages. Customizing the success message appearance typically requires the JavaScript solutions shown above or custom CSS.
By leveraging these JavaScript events, you can significantly extend the default post-submission behavior of Contact Form 7 to create a smoother user experience tailored to your website's needs.
Related Support Threads Support
-
question about using CF 7 for monthly newsletter listhttps://wordpress.org/support/topic/question-about-using-cf-7-for-monthly-newsletter-list/
-
After submit – how can I customise?https://wordpress.org/support/topic/after-submit-how-can-i-customise/
-
Creating a funnel with CF7https://wordpress.org/support/topic/creating-a-funnel-with-cf7/
-
Integration with Houzez CRMhttps://wordpress.org/support/topic/integration-with-houzez-crm/
-
@plugin creatorshttps://wordpress.org/support/topic/plugin-creators/
-
POST MY CF7 FORMhttps://wordpress.org/support/topic/post-my-cf7-form/
-
Multiple forms in 1 page and using 1 Submit buttonhttps://wordpress.org/support/topic/multiple-forms-in-1-page-and-using-1-submit-button/
-
adding submissions to a pagehttps://wordpress.org/support/topic/adding-submissions-to-a-page/
-
Form Elements for Application not contact Formhttps://wordpress.org/support/topic/form-elements-for-application-not-contact-form/
-
Trash for deleted formshttps://wordpress.org/support/topic/trash-for-deleted-forms/
-
Star rating for feedbackhttps://wordpress.org/support/topic/star-rating-for-feedback/
-
How to prevent form to redirect to thank you pagehttps://wordpress.org/support/topic/how-to-prevent-form-to-redirect-to-thank-you-page/
-
Idea: Ctrl-S to save edited formhttps://wordpress.org/support/topic/idea-ctrl-s-to-save-edited-form/
-
Sending Custom HTMLhttps://wordpress.org/support/topic/sending-custom-html/
-
Add from CF7 views of columns instead rowshttps://wordpress.org/support/topic/add-from-cf7-views-of-columns-instead-rows/
-
Make form title translatablehttps://wordpress.org/support/topic/make-form-title-translatable/
-
How can I view a list of contacts?https://wordpress.org/support/topic/how-can-i-view-a-list-of-contacts/
-
User-Generated Posts From Front End Submission?https://wordpress.org/support/topic/user-generated-posts-from-front-end-submission/
-
PUBLISH “NAME” FROM FORM SUBMISSIONhttps://wordpress.org/support/topic/publish-name-from-form-submission/
-
I would like to redirect to a thank you page after filling out the formhttps://wordpress.org/support/topic/i-would-like-to-redirect-to-a-thank-you-page-after-filling-out-the-form/
-
Best way to implementhttps://wordpress.org/support/topic/best-way-to-implement/
-
Is it possible to put a post in a section?https://wordpress.org/support/topic/is-it-possible-to-put-a-post-in-a-section/
-
Insert nextgen gallery image data into a formhttps://wordpress.org/support/topic/insert-nextgen-gallery-image-data-into-a-form/
-
Create a form / exercise for studentshttps://wordpress.org/support/topic/create-a-form-exercise-for-students/
-
tracking in google analytics and google adshttps://wordpress.org/support/topic/tracking-in-google-analytics-and-google-ads/
-
How do you place the answer field below the question for quiz?https://wordpress.org/support/topic/how-do-you-place-the-answer-field-below-the-question-for-quiz/
-
Auto-fill a custom field in the Contact Form 7https://wordpress.org/support/topic/auto-fill-a-custom-field-in-the-contact-form-7/
-
User visibility ruleshttps://wordpress.org/support/topic/user-visibility-rules/
-
About adding a link in the success messagehttps://wordpress.org/support/topic/about-adding-a-link-in-the-success-message/
-
Flamingo / WordPress Multi-Site Exporthttps://wordpress.org/support/topic/flamingo-wordpress-multi-site-export/
-
Print Formhttps://wordpress.org/support/topic/print-form-6/
-
Form results formattedhttps://wordpress.org/support/topic/form-results-formatted/