表单提交返回空白页

问题描述 投票:0回答:1

我有一份到目前为止效果很好的联系表格。然而,由于我在网站上创建了一个php路由器,提交表单后,虽然它重定向到操作网站(thank-you.php),但该网站的内容只是一个空白页面(正文中没有HTML内容,我使用开发工具检查),并且消息未到达适当的电子邮件地址。如果我在表单提交页面上 var_dump $_POST 变量,则不会显示任何值。

我怀疑问题与路由器有关。作为测试,我在每个路由之前放置了一个“打印”PHP 命令,其中包含按升序排列的数字。我将感谢页面(表单提交页面)直接放在索引页面之后,以排除代码是否卡在其他路线上。奇怪的是,虽然每个子页面只打印出给定页面在路由器中的位置之前的数字,但感谢页面打印出所有数字,即那些也只会出现在路由器中的数字。队列...我将非常感谢您对这个问题的帮助。预先感谢您。

HTML(表单):

                <form class="contact-form" method="POST" action="/thank-you">

                    <input type="text" id="website" name="website" />

                    <div class="contact-wrapper name">
                        <label for="name">
                            <?php echo $lang["contact-name"] ?>
                        </label>
                        <input type="text" id="name" name="name" placeholder="<?php echo $lang['name-placeholder'] ?>" required>
                    </div>
                    <div class="contact-wrapper email-and-phone">
                        <div>
                            <label for="email">E-mail</label>
                            <input type="text" id="email" name="email" placeholder="<?php echo $lang['email-placeholder'] ?>" required>
                        </div>

                        <div>
                            <label for="telephone">
                                <?php echo $lang["contact-telephone"] ?>
                            </label>
                            <input type="text" id="telephone" name="telephone" placeholder="<?php echo $lang['telephone-placeholder'] ?>">
                        </div>
                    </div>
                    <div class="contact-wrapper subject">
                        <label for="subject">
                            <?php echo $lang["contact-subject"] ?>
                        </label>
                        <input type="text" id="subject" name="subject" placeholder="<?php echo $lang['subject-placeholder'] ?>" required>
                    </div>

                    <div class="contact-wrapper message">
                        <label for="message">
                            <?php echo $lang["contact-message"] ?>
                        </label>
                        <textarea id="message" name="message" placeholder="<?php echo $lang['message-placeholder'] ?>" style="height:200px" required></textarea>
                    </div>
                    <input type="submit" id="submit" name="submit" value="<?php echo $lang['contact-submit'] ?>">
                </form>

PHP(表单提交页面):

<?php

// exit if accessed directly.
defined('ABSPATH') || die(header('location: /home'));

if (isset($_POST['submit']) && $_POST['submit'] != '' && $_POST['submit'] != null) {

    $name = $_POST['name'];
    $mailFrom = $_POST['email'];
    $telephone = $_POST['telephone'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    $mailTo = "[email protected]";
    $txt = "You have received an e-mail from " . $name . ".\n\n" . "E-mail: " . $mailFrom . ".\n\n" . "Telephone: " . $telephone . ".\n\n" . $message;

    mail($mailTo, $subject, $txt);
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset='UTF-8' />
    <title>Thank you!</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
    <div class="thank-you-wrapper">
        <p>Thank you for reaching out to us. We will get back to you shortly. Please click <a href="/home" style="text-decoration: none; color: #0986d9;">here </a> if you are not redirected within a few seconds.
</p>
    </div>
    <script>
        setTimeout(function() {
            window.location.replace("/home"); // will redirect to main page
        }, 3000); // will call the function after 3 secs.
    </script>
</body>

</html>

PHP(路由器):

<?php

require_once __DIR__ . '/router.php';

// ##################################################
// ##################################################
// ##################################################

// Static GET
// In the URL -> http://localhost

print '1';
// The output -> Index
get('/', 'pages/index.php');

print '2';
// The output -> Thank You
get('/thank-you', 'pages/thank-you.php');

print '3';
// The output -> About
get('/about', 'pages/about.php');

print '4';
// The output -> Services
get('/services', 'pages/services.php');

print '5';
// The output -> Web
get('/web', 'pages/web.php');

print '6';
// The output -> Contact
get('/contact', 'pages/contact.php');
``````````````````````````````````````````````````````
php html forms contact-form
1个回答
0
投票

路由器将

/thank-you
定义为
GET
:

get('/thank-you', 'pages/thank-you.php');

当您的表格通过

POST
发送时:

<form class="contact-form" method="POST" action="/thank-you">
© www.soinside.com 2019 - 2024. All rights reserved.