简体   繁体   English

联系表格 7:提交后如何将表格替换为 HTML 代码?

[英]Contact Form 7: How to replace the form with an HTML code after submission?

I am developing a web form with WordPress and Contact Form 7 .我正在开发带有WordPressContact Form 7的 web 表格。 The form is working OK.表格工作正常。 However, I want the entire form to be replaced with a thank you message and an image.但是,我希望将整个表格替换为感谢信息和图片。 I don't want to redirect to a thank you page.我不想重定向到感谢页面。 I want to just replace the form and stay on the same page.我只想替换表单并留在同一页面上。 Can you understand?你能明白吗?

Can anyone point me to a solution?谁能指出我的解决方案?

Thanks.谢谢。

You should use DOM Events as stated on this Contact Form 7 Documentation Page您应该使用此联系表 7 文档页面中所述的 DOM 事件

For your example the code could look like this:对于您的示例,代码可能如下所示:

script.js脚本.js

document.addEventListener( 'wpcf7submit', function( event ) {
  let form = document.getElementsByClassName("myForm");
  let thankYouMessage = document.getElementsByClassName("thankYou");

  form.style.display = 'none';
  thankYouMessage.style.display = 'block';

}, false );

your HTML file:你的 HTML 文件:

<form class="myForm">
</form>

<div class="thankYou">
<img src="" />
<h2>Thank you for your submit!</h2>

</div>

Now just set display:none;现在只需设置display:none; for the container with class thankYou and you are good to go!对于带有thankYou的容器,谢谢您,一切顺利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM