【问题标题】:Unable to get informations from a Html5 CSS and php form无法从 Html5 CSS 和 php 表单获取信息
【发布时间】:2015-07-12 17:59:00
【问题描述】:

我尝试构建一个 html5 表单并将信息发送到 form.php

<h3>Contact Me</h3>
<p></p>
<form method="post" action="form.php">
    <div class="row uniform">
        <div class="6u 12u(xsmall)">
            <input type="text" name="name" id="name" placeholder="Name" />
        </div>
        <div class="6u 12u(xsmall)">
            <input type="email" name="email" id="email" placeholder="Email" />
        </div>
    </div>
    <div class="row uniform">
        <div class="12u">
            <input type="text" name="subject" id="subject" placeholder="Subject" />
        </div>
    </div>
    <div class="row uniform">
        <div class="12u">
            <textarea name="message" id="message" placeholder="Message" rows="6"></textarea>
        </div>
    </div>
    <div class="row uniform">
        <div class="12u">
            <ul class="actions">
                <li>
                    <input type="submit" class="special" value="Send Message" />
                </li>
                <li>
                    <input type="reset" value="Reset Form" />
                </li>
            </ul>
        </div>
    </div>
</form>

在同一个地方我有 form.php

<?
if (isset($_POST['name']) && isset($_POST['email'])) {
    echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>

当我点击提交时form.php 页面打开但空白。

【问题讨论】:

  • 开始标签 &lt;?php 而不是 &lt;?
  • 您的网络服务器是否配置为处理(执行).php 文件?

标签: php css html forms


【解决方案1】:

使用 PHP,您可以使用此代码重定向到另一个页面:

header("Location: index.html");
die();

但要注意——它只有在之前没有输出的情况下才会起作用!

或者,如果您必须早点提供一些输出,您可以只回显 Javascript 来重定向:

echo '<script type="text/javascript">
           window.location = "http://www.google.com/"
      </script>';

【讨论】:

    【解决方案2】:

    是的,抱歉,现在我可以通过邮件发送了。

    <?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: lespizz'; 
    $to = 'jim@fdfrdsfg.com'; 
    $subject = 'Hello';
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    mail ($to, $subject, $body, $from)
    ?>
    

    你知道如何自动返回 index.html 吗?

    谢谢

    【讨论】:

    • 您的 mail() 函数缺少分号。对于重定向,您可以使用 header('Location:index.html'); 或 javascript window.history.back();window.location.href = 'index.html';
    【解决方案3】:
    <?php
    if (isset($_POST['name']) && isset($_POST['email'])) {
    echo 'name '.$_POST['name'].' mail '.$_POST['email'];
    }
    ?>
    

    我认为您错过了 PHP 标记的开头 &lt;?php 而不是 &lt;?

    【讨论】:

      猜你喜欢
      • 2013-05-13
      • 2013-03-18
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多