0

I'm trying to make my form pass a parameter to a link like this :

index.php?action=2&parameter=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.

2
  • 4
    Use action="index.php" then add a hidden input for the action - <input type="hidden" name="action" value="2" /> Commented Nov 18, 2013 at 15:11
  • @Fredd: Okay, deleted my previous comment. (This one will self-destruct in a bit, too) Commented Nov 18, 2013 at 15:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Amal, that's exactly what I was looking for. FDL's advise was nearly working, but it didn't assing the value so the link looked like action=&parameter=value. This one however, works perfectly fine. Thank you!
@Abbys: Glad to have been of help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.