首页 > 解决方案 > 如何获取文本输入并将其粘贴到使用 PHP 的链接前面?

问题描述

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

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>

标签: phphtml

解决方案


<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);

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


推荐阅读