0

I have a problem with creating a simple search form, used to search my database.

I started using the POST-method and everything worked fine, but switched to using GET-method instead to be able to bookmark my search results. But now I have trouble with the "action-url" when posting.

<form action="index.php?page=searchresult'" method="post">

This worked fine, I got my var's sent to the stated URL, but

<form action="index.php?page=searchresult" method="get">

Doesn't work. When I check my HTML code everything looks great, but I end up going to the URL

site.com/index.php?ALL THE GET-variables linedup here.

I am loosing the "?page=searchresult" part when using the GET-method?!

Am I missing something here, please help?!

Humble regards :)

1
  • Can you share your actual php code here Commented Oct 9, 2013 at 9:55

6 Answers 6

1

Try changing this to

<form action="index.php?page=searchresult" method="get">

Put the page element as a hidden tag.

<form action="index.php" method="get">
<input type="hidden" name="page" value="searchresult"/>
<!-- Rest of the input elements -->
<input type="submit" />
</form>

This should fix your issue.

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

1 Comment

As usual the answer is so obvious when you get it presented. :P Code changed, and it works, thanks all! :)
0

If you are using GET methood then you can pass page parameter in hidden field like

<input type="hidden" name="page" value="searchresult">

Comments

0

GET sends data in the query string. If the URL in the action has a query string, it will be overwritten by the new one generated by the form.

Store your data in hidden inputs instead.

Comments

0

Well, this is interesting, but you can fix it using an hidden <input>, such as this:

<form action="index.php" method="get">
<input type="hidden" name="page" value="searchresult" />
            <input type="submit" value="submit" />
</form>

Just compile the "value" of the hidden input with what you need to pass.

Tried it and it actually works.

Edit:

obviously, from php, use this:

<?php $page = ((isset($_GET['page'])?($_GET['page']):("nope")); ?>

Comments

0

Add a hidden page data in the form.

<form action="index.php" method="get">
<input type="hidden" name="page" value="searchresult" />

Simply because "page=searchresult" is a get data.

Comments

0

You have a quote too much, try removing it.

                                         |   
                                        \|/
<form action="index.php?page=searchresult'" method="post">

1 Comment

Aah, sry, just a mistype, my bad ! :(

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.