Page 1 of 1

How to post a keyword, then 'back' but not lose the post???

Posted: Thu Jun 16, 2011 3:37 pm
by simonmlewis
Hi

For years I have used a standard <form method='post'> type form to $_POST data to a search page.

Someone then sees the results, clicks a result, and then decides to go BACK a page in the browser. But in doing that (you may know what's coming...) you are asked "RETRY?".

How do I stop it doing that, so it just goes back and there are the results? I'm sure it is something to do with the _GET, _REQUEST, _POST type query, but am a little lost.

Hope something can help with what I suspect is a very straightward answer.

Regards
Simon

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 3:43 pm
by AbraCadaver
Post is only required when you're taking an action with a consequence (add, update, delete, send email, etc). This is perfectly fine for retrieval and will get rid of your problem:

[text]<form method="get" action="results.php">[/text]
Then make sure to use $_GET on the results.php page.

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 3:50 pm
by simonmlewis
Fatal error: Call to undefined function getPage()
It's on line 444, which is:

Code: Select all

<?php
	getPage();
	?>
Why on earth would it have an affect on that?
The page, index.php?page=search, uses

Code: Select all

if(isset($_GET['search']))
{
    $search = $_GET['search'];
    $_SESSION['search']=$search;
} else {
    $search=$_SESSION['search'];
}

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 3:51 pm
by simonmlewis
Hold on, it' sbecause it changes the URL to:
index.php?search=bulldog
Yet it's missing "page=search&menu=home".

how do I keep that url structure??

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 4:01 pm
by AbraCadaver
[text]<form method="get" action="index.php?page=search&menu=home">[/text]

Or try leaving the action blank.

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 4:05 pm
by simonmlewis
tried that:
"<form method='POST' action='index.php?page=search&menu=home' name="searchbox" onSubmit="return formCheck(this)">".
This is what caused that problem.

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 4:18 pm
by AbraCadaver
simonmlewis wrote:tried that:
"<form method='POST' action='index.php?page=search&menu=home' name="searchbox" onSubmit="return formCheck(this)">".
This is what caused that problem.
Caused what problem? The original back button problem or the new undefined function problem? What is the working form code?

Re: How to post a keyword, then 'back' but not lose the post

Posted: Thu Jun 16, 2011 4:21 pm
by simonmlewis
That caused the getpage problem, because "page" wasn't in the url, as it replaced it with 'search='.
I used what was suggested, but it failed and caused that error. And when I look at the page, it's obvious why it caused the error, because it changed the URL and broke the getpage query.

Re: How to post a keyword, then 'back' but not lose the post

Posted: Fri Jun 17, 2011 3:07 am
by simonmlewis
My getPage() query looks for "page=" in the URL.
So when I use that GET form, it get rids of the "page=" and just has "search=" and as a result, it cause the error.

Do you somehow place "search=" into the URL manually??

How do you do it?

Re: How to post a keyword, then 'back' but not lose the post

Posted: Fri Jun 17, 2011 4:12 am
by simonmlewis
And the answer, after some more research.... is:

Code: Select all

<form method='GET' action='index.php' name="searchbox"  onSubmit="return formCheck(this)">
<input type='hidden' name='page' value='search'>
<input type='hidden' name='menu' value='home'>
You have to post 'page' and 'menu' thru as separate hidden fields, and tell it what to put in those fields, to grasp it in the 'GET' in the URL.

Works perfectly.

Re: How to post a keyword, then 'back' but not lose the post

Posted: Fri Jun 17, 2011 10:45 am
by AbraCadaver
simonmlewis wrote:And the answer, after some more research.... is:

Code: Select all

<form method='GET' action='index.php' name="searchbox"  onSubmit="return formCheck(this)">
<input type='hidden' name='page' value='search'>
<input type='hidden' name='menu' value='home'>
You have to post 'page' and 'menu' thru as separate hidden fields, and tell it what to put in those fields, to grasp it in the 'GET' in the URL.

Works perfectly.
You are correct, sorry... When using post, you can append a get query string to the action, but it seems when you use get you cannot.