How to post a keyword, then 'back' but not lose the post???
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How to post a keyword, then 'back' but not lose the post???
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
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
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
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.
[text]<form method="get" action="results.php">[/text]
Then make sure to use $_GET on the results.php page.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
It's on line 444, which is:Fatal error: Call to undefined function getPage()
Code: Select all
<?php
getPage();
?>The page, index.php?page=search, uses
Code: Select all
if(isset($_GET['search']))
{
$search = $_GET['search'];
$_SESSION['search']=$search;
} else {
$search=$_SESSION['search'];
}Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
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??
index.php?search=bulldog
Yet it's missing "page=search&menu=home".
how do I keep that url structure??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
[text]<form method="get" action="index.php?page=search&menu=home">[/text]
Or try leaving the action blank.
Or try leaving the action blank.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
tried that:
"<form method='POST' action='index.php?page=search&menu=home' name="searchbox" onSubmit="return formCheck(this)">".
This is what caused that problem.
"<form method='POST' action='index.php?page=search&menu=home' name="searchbox" onSubmit="return formCheck(this)">".
This is what caused that problem.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
Caused what problem? The original back button problem or the new undefined function problem? What is the working form code?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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
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?
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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
And the answer, after some more research.... is:
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.
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'>
Works perfectly.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How to post a keyword, then 'back' but not lose the post
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.simonmlewis wrote:And the answer, after some more research.... is:
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.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'>
Works perfectly.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.