【问题标题】:Pre fill form using the URL bar使用 URL 栏预填表单
【发布时间】:2014-04-25 12:50:00
【问题描述】:

我有一个表单,我需要它首先使用 URL 为几个字段插入数据。我在下面附上了我的表格样本。我们使用 PHP 将其发布到 mySQL 数据库中。我不介意它是如何进入那里的。但是我已经看到了使用 example.com/form.php?add_1=10 The Street 的示例,这对我来说是最好的方式。

谢谢,

<form role="form" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="epicform">
<input type="text" class="form-control" id="lastname" name="surname" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_1" name="add1" placeholder="Address Line 1" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_2" name="add2" placeholder="Address Line 2" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_3" name="add3" placeholder="Address Line 3" required style="
height: 35px;
">
<input type="text" class="form-control" id="postcode" name="postcode" placeholder="Postcode" required style="
height: 35px;
">
<input type="text" class="form-control" id="phone_number" name="phoneNum" placeholder="Phone Number" required style="
height: 35px;
">
</form>

我已经在这里尝试了一个 javascript 解决方案,但我似乎无法让它做任何事情。

【问题讨论】:

  • 询问代码的问题应该表明对正在解决的问题的基本理解。包括尝试的解决方案、它们为什么不起作用以及预期的结果。另见:Stack Overflow question checklist.
  • 我已经尝试过stackoverflow.com/questions/14070105/…,但我似乎无法让它做任何事情!
  • @JohnConde 关闭选项发生了什么?那是有史以来最好的一次。 (我看到你已经存档了);-) 所以应该把它放回去。+1(我想我会自己保留一份副本)。
  • 我也喜欢它,但 SO 觉得有更好的方法来做到这一点。我认为这些总结了这个问题很好地。因此,我仍然使用它。
  • 是的,它确实很好地总结了它。 @JohnConde 我正在保存它以备将来使用。

标签: php mysql forms


【解决方案1】:
<form role="form" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="epicform">

<input type="text" class="form-control" id="add_1" name="add1" value="<?php echo $_GET['add1']; ?>" placeholder="Address Line 1" required style="height: 35px;">

</form>

现在您的网址必须有效! http://example.com/form.php?add_1=10

【讨论】:

    【解决方案2】:

    你需要的是这个:http://www.php.net/manual/en/reserved.variables.get.php

    http://urlToYourScript.php?add1=Randomstreet

    <input type="text" class="form-control" id="add_1" name="add1" 
    placeholder="<?php echo $_GET['add1']; ?>" required style="height: 35px;">
    

    【讨论】:

    • 工作愉快!干杯队友!
    • 请将答案标记为正确,以供将来参考。谢谢。
    • 现在完成。干杯@user3348022
    猜你喜欢
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    相关资源
    最近更新 更多