Reputation: 137
I'm trying to make my form pass a parameter to a link like this :
index.php?action=2¶meter=value
Instead, all it does is pass the parameter like this:
index.php?parameter=value
This is my code :
<form class="navbar-form navbar-left" action="index.php?action=2" method="get" name="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="put something here...." name="search" width="100">
</div>
<button type="submit" class="btn btn-default">search</button>
</form>
The form is located in my index.php?action=2 template but is passing the parameter back to the original index.php file instead of index.php?action=2 file.
I want to use the parameter later as a $_GET with few more parameters in order to search and sort the data taken from DB. The DB php code I wrote works fine, and when I create the link myself it all works nice, but not in the scenario when I try to type the search value in the textbox.
How do I avoid that ?
Thanks in advance!
Edit :
I have a switch in my index.php file which does :
case 2:
include "_template/__test.php";
break;
My form is located in the above __test.php file.
Upvotes: 0
Views: 407
Reputation: 76656
What you're trying to do can be accomplished by using a hidden field. Add the following input field in your form:
<input type="hidden" name="action" value="<?php echo $_GET['action']; ?>" />
So, when you pass the action
parameter, it will generate an input field with the sent value ($_GET['action']
) and will be passed to the PHP script when the form is submitted.
Upvotes: 1