[英]For a Single-Page-Website with a form at the end: Do I have to convert the index.html into index.php?
我正在第一个网站上工作! 它的单页设计在页面末尾带有一个简单的联系表单(两个输入字段,一个文本区域以及一个复选框和提交按钮)! 页面已准备好……唯一缺少的是联系表单的PHP。 提交联系表单后,我想在同一页面上显示一条消息(消息已传递)! 我的问题:为此,我需要将整个index.html转换为index.php吗? 这似乎是表单的action属性保留在同一页面上的唯一方法! 还是为此目的还添加Ajax更好? 所有教程都使用index.php ...
请帮忙!
我会说是的,使其成为.php文件。 一个PHP文件中可以包含纯HTML。 您的index.php可能看起来像这样:
<?php
if ( isset( $_POST['submitted'] ) ) {
$message = 'Your email has been sent!';
// Process your form and send email here
}
?>
<html>
<head>
...
</head>
<body>
<?php
if ( $message ) {
echo "<div class='message'>$message</div>";
}
?>
<!--The rest of your body...-->
</body>
</html>
当您在页面中用PHP语言编写一行代码时,必须将page.html转换为page.php
显示一条消息尝试使用此
echo "<script> alert('message delivered '); window.location.href='index.php';</script>" ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.