【问题标题】:How to get text input and paste it in front of a link using PHP?如何获取文本输入并将其粘贴到使用 PHP 的链接前面?
【发布时间】:2019-03-21 19:45:08
【问题描述】:

我目前正忙于(重新)制作荷兰语维基百科网站。我想做搜索栏。我的想法是获取文本输入,当您单击搜索时,文本将转到链接的前面,如下所示:

https://ibb.co/XbndsKP

这是目前的搜索栏:

<div align='center'>
    <form method="submit" action='php/zoeken.php'>

        <input placeholder="zoeken"id="zoeken"class='zoeken'type="text">
        <button class='button'type="submit">zoeken</button>
</div>

【问题讨论】:

  • 你的问题或问题是?顺便说一句,您的 FORM 没有正确关闭,我认为您不会收到任何发布请求...
  • 处理提交数据的代码在哪里?

标签: php html


【解决方案1】:
<form action="THE PAGE YOU SENT REQUEST" method="POST">
  <input placeholder="zoeken" name="zoaken" type="text">
  <input type="submit" value="Submit">
</form>

<?php 

  /* Get the text input with $_POST */
  $string = $_POST['zoaken'];

  /* Redirect the page to the new address */
  header('Location: https://nl.wikipedia.org/wiki/'.$string);

您还应该检查文本是否为空、空或有漏洞。

【讨论】:

    【解决方案2】:

    更好的方式是使用 JS。像这样获取输入值并重定向

    document.location = 'http://nl.wikipedia.com/search_word';
    

    【讨论】:

    • 为什么“必须” OP 使用 JS?这可能是一个不错的选择,但“必须”有点太绝对了。
    • 因为它更简单,所以 PHP 有很多验证
    • 你没有理解我的意思。 OP 不必必须为此使用 JS。就像我说的,这可能是一个不错的选择,但是说 OP“必须”使用它是不准确的。 “必须”的意思是没有JS就不行,它可以。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 2022-06-23
    相关资源
    最近更新 更多