通过链接自动回答PHP表单问题

时间:2015-09-05 17:20:14

标签: php

我正在使用PHP联系表单模板。我希望它通过链接自动输入答案。

我的意思是,当您点击此链接时 (http://minecraft-accounts.org/contact/index.php?account=Test

它会自动填写帐户部分的答案。但是当您输入普通链接(http://minecraft-accounts.org/contact/index.php

所有方框都是空白的。我如何制作模板表格可以做到这一点?

以下是来自互联网的表格代码? code

3 个答案:

答案 0 :(得分:2)

在这种情况下,如果你想从url传递数据,你可以在html元素中使用它:

<input type="text" value="<?PHP echo $_GET['account'] ?>"/> 当然你也可以使用聪明的变量!!!

答案 1 :(得分:2)

非常简单。在您提供的URL中设置一个名为account的查询字符串。你也可以这样做......

例如您的网址:www.abc.com?account = 123 然后代码会喜欢这个

  <input type="text" value="<?php echo $_GET["account"] ?>">

答案 2 :(得分:1)

如果变量isset();,我会检查 所以你的coude应该看起来像那样

<html>
    <head>
        <title>My Webpage</title>
    </head>
    <body>
        <?php
            $account = "";
            $mail = "";
            $message = "";

            if(isset($_GET['account'])) {
                $account = $_GET['account'];
            }

            if(isset($_GET['mail'])) {
                $mail = $_GET['mail'];
            }

            if(isset($_GET['message'])) {
                $message = $_GET['message'];
            }
        ?>
        <table border="0">
            <tr>
                <td>Account-Name:</td>
                <td>
                    <input type="text" value="<?php echo $account; ?>">
                </td>
            </tr>
            <tr>
                <td>Mail:</td>
                <td>
                    <input type="mail" value="<?php echo $mail; ?>">
                </td>
            </tr>
            <tr>
                <td>Message:</td>
                <td>
                    <textarea>
                        <?php echo $message; ?>
                    </textarea>
                </td>
            </tr>
        </table>
    </body>
</html>

因此,网址可以是:http://www.example.com/register.php?account=DonaldDuck&message=Hello%20my%20name%20is%20Donald

输入AccountMessage已填满。

它也可以是:http://www.example.com/register.php?account=DonaldDuck,它仍可正常运行。

有关详细信息,请参阅:http://php.net/manual/de/function.isset.php

相关问题