Remove the Form on Contact Form 7 WordPress plugin after the submission

To remove form fields on a contact form that uses Contact Form 7 WordPress plugin after the successful submission, add this code to the functions.php file in the WordPress installation:

add_action( 'wp_footer', 'mycustom_wp_footer' );
 
function mycustom_wp_footer() {
?>
<script type="text/javascript">
/* <![CDATA[ */
document.addEventListener( 'wpcf7mailsent', function( event ) {
  jQuery(".wpcf7-form.sent").find('p').hide();
}, false );
/* ]]> */
</script>
<?php
}