简体   繁体   中英

How to pass input value to href

I have a form with method post and with a text box and button to submit.

I can easily grab the value with $_POST but I want to be able to pass this value to a link.

textinput = search term

link = index.php?search=search term

If I just concoctenante it into the href I get the value $search isn't set because $search gets set on $_POST .

I know this is possible, wowhead.com is an example, although id rather not use javascript, just css html and php.

Thanks!

Using form method get works but it also passes my button value to the url

<form action="search.php" method="get">
    <table style="border:0px">
        <tr>
            <td style="border:0px">
                <input id="search" name="search" autocomplete="off" type="text" maxlength="32" style="width:350px;" />
            </td>
            <td style="border:0px">
                <input name="submit" type="submit" value="Search" style="font-size:16;padding:3px;" />
            </td>
        </tr>
    </table>
</form>

Shows up like this:

http://localhost/search.php?search=searchterm&submit=Search

I want to not have &submit=Search

FIXED by changing

<input name="submit" type="submit" value="Search" style="font-size:16;padding:3px;" />

to (got rid of name tag)

<input type="submit" value="Search" style="font-size:16;padding:3px;" />

use get method

<form action="index.php" method="GET">
    <input type="search" name="search" />
    <input type="submit" name="submit" />
</form>

OR

<form action="index.php" method="GET">
    <input type="search" name="search" />
</form>

and in php you grab the value by $_GET['search']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM