0

I have a search field, that creates the URL for example: mypage.com/action.php?srch=rabbit

<div class="col-md-2">
    <form action="action.php" method="get" role="search" style="margin-top:20px">
        <div class="input-group">
            <input style="margin-top:0px" type="text" class="form-control" placeholder="Suchen..." name="srch" id="srch">
                <div class="input-group-btn">
                <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
            </div>
        </div>
    </form>
</div>

But I need to create a link that is mypage.com/action.php?id=12&srch=rabbit

So I changed this line:

<form action="<?php echo "action.php?id=".$id; ?>" method="get" role="search" style="margin-top:20px">

But unfortunately the result is still: mypage.com/action.php?srch=rabbit

peace_love
  • 6,229
  • 11
  • 69
  • 157

2 Answers2

4

Add the required additional field in a hidden input.

<input name="id" value="<?php echo $id; ?>" type="hidden">

Code will look like this.

<div class="col-md-2">
    <form action="action.php" method="get" role="search" style="margin-top:20px">
        <div class="input-group">
            <input style="margin-top:0px" type="text" class="form-control" placeholder="Suchen..." name="srch" id="srch">
            <input name="id" value="<?php echo $id; ?>" type="hidden">
                <div class="input-group-btn">
                <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
            </div>
        </div>
    </form>
</div>
Imesha Sudasingha
  • 3,462
  • 1
  • 23
  • 34
2

Add a hidden input:

<input type="hidden" name="id" value="<?php echo $id; ?>">
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87