我正在我的第一个网站上工作!它是一个单页设计,在页面末尾有一个简单的联系表单(两个输入字段、一个文本区域和一个复选框和提交按钮)!页面已准备就绪……唯一缺少的是联系表单的 PHP。当提交联系表单时,我想在同一页面上显示一条消息(已发送消息)!我的问题:为此我需要将整个 index.html 转换为 index.php 吗?这似乎是表单的action属性保持在同一页面的唯一途径!或者最好为此目的还添加 Ajax?所有教程都使用 index.php...
2 回答
慕慕森
TA贡献1856条经验 获得超17个赞
我会说是的,让它成为一个 .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>
潇湘沐
TA贡献1816条经验 获得超6个赞
当您在页面中用 PHP 语言编写一行时,您必须将 page.html 转换为 page.php
显示消息尝试使用这个
echo "<script> alert('message delivered '); window.location.href='index.php';</script>" ;
- 2 回答
- 0 关注
- 215 浏览
添加回答
举报
0/150
提交
取消