简体   繁体   English

联系表单HTML,返回.html文件中的“成功”文本

[英]Contact form HTML, Returning a “Success” text in the .html file

i have this question and i can't find a solution. 我有这个问题,我找不到解决方案。 I'm pretty new in the programming. 我在编程方面很陌生。 So.. 所以..

my HTML file with the form is contact.html (straight html file) 我的HTML文件与表单是contact.html(直接html文件)

The php code is in separated file. php代码在单独的文件中。 So, everythings work fine, but.. I want to have the return text for the "success" or "fail" in the in my html file (let's say under the submit button). 所以,每一件事都很好,但是..我希望在我的html文件中有“成功”或“失败”的返回文本(让我们说在提交按钮下)。 Is it possible if it's not php file with html code, but straight html. 是否有可能,如果它不是带有HTML代码的php文件,而是直接的html。 And can you tell me what should I do? 你能告诉我该怎么办?

I hope you understand me. 我希望你能理解我。

Straight HTML can't give different content conditionally. 直接HTML无法有条件地提供不同的内容。

You could get something that resembles what you describe by placing an iframe after the form and target ing it with the form. 您可以通过在表单后放置iframe并使用表单将其作为target来获得与您描述的内容类似的内容。 As solutions go, that's rather ugly. 随着解决方案的进行,这是相当丑陋的。

You could use JavaScript to send the form data to the PHP file and then modify the DOM of the HTML document based on the response (Ajax), but that would be unnecessarily complex and violate the best practise of unobtrusive JavaScript . 您可以使用JavaScript将表单数据发送到PHP文件,然后根据响应(Ajax)修改HTML文档的DOM,但这会不必要地复杂并违反不引人注目的JavaScript的最佳实践。

The usual approach to this problem is to have a PHP file being the single entry point for all things relating to the form (it can keep parts of its logic or HTML in other files and include() them as needed) and have it decide, based on what input receives, if it should show: 解决这个问题的常用方法是让PHP文件成为与表单相关的所有内容的单一入口点(它可以将其逻辑或HTML的一部分保存在其他文件中,并根据需要include() )并让它决定,根据输入收到的内容,如果显示:

  • The plain form 简单的形式
  • The form with error messages (and pre-populated with the user's incorrect submitted data) 带有错误消息的表单(并预先填充了用户提交的错误数据)
  • The thank-you 谢谢你

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

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