douyu0852 2019-07-01 20:52
浏览 122
已采纳

对于最终有表单的单页网站:我是否必须将index.html转换为index.php?

I am working on my first Website! Its a Single Page Design with a simple contact form (two input fields, a textarea and a checkbox and submit button) at the end of the page! The page is ready... the only thing that´s missing is the PHP for the contact form. When the contact form is submitted I would like to show a message (message delivered) on the same page! My Question: For this purpose do I need to convert the whole index.html to index.php ?? It seems to be the only way for the action attribute of the form to stay on the same page! Or is it better to add also Ajax for this purpose? All tutorials use the index.php...

Please help!

  • 写回答

2条回答 默认 最新

  • dqsk4643 2019-07-01 20:58
    关注

    I would say yes, make it a .php file. A PHP file can have plain HTML in it. Your index.php could look something like this:

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探