Re-passing post data silently

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Re-passing post data silently

Post by Galahad »

I'm making a simple search engine for a site. It works great now, but will display all of the results on one page. I am attempting to make it gracefully return 10 results at a time. I need to read both get and post data (at least the way I have it set up now). To do so, I'm using this:

Code: Select all

$input = strtolower($_REQUESTї'searchtext']);
$offset = $_REQUESTї'offset'];
if (!$offset) $offset = 0;
That works fine. Next I have it read the data from the database (dba, really simple), and select just the 10 that I want for display using this code:

Code: Select all

$results2 = array_slice($results, $offset, 10);
At the bottom I have a the prev/next kind of set up where like this:

Code: Select all

if ($offset+10 <= $count) echo "<a href='$PHP_SELF?searchtext=$input&offset=".($offset+10)."'>Next</a> ";
where $count is the total number of results. I have similar stuff for the prev link. It works fine, but the url in the browser window ends up getting kind of garbled. I don't mind having the offset number passed visibly, but is there a way I can just resend the current post data (the searchtext)without having to include it in the url? Thanks for the help.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you may try

Code: Select all

<form method="POST"><input type="hidden" name="&#1111;key]" value="&#1111;value]">....</form>
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

yep hidden fields seems to work for these kinda things the best, that's what i use for my search scripts...
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

Thanks for the suggestion. I couldn't get it to work, though. I have a fairly limited knowledge about html forms, so I may be trying to do something that isn't possible. I can't seem to make it submit the form data to the next page. I don't want to make a submit button for that form (I want my "Prev 1 2 3 Next" kinds of links to submit it), so I can't seem to make it actually submit the data. This is my form:

Code: Select all

<form method="POST"><input type="hidden" name="searchtext" value="<?php echo $input ?>"><input type="hidden" name="log" value="true"></form>
I want it to submit that data when you click a link to the next page. However, it's not getting sent. Is there a way to submit data without the user needing to push a submit button?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The only way to do that would be to use Javascript and then people who don't have Javascript or have it disabled won't be able to use your form. There are, however, a couple of work arounds, try this:

http://www.evolt.org/article/Forms_and_ ... index.html

Mac
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

Thanks for the help, I just gave up on the form and tried sessions. That gave me some weird, inconsistent trouble, though. I've gone to just passing the search string on the url with a get. If it's good enough for google, it's good enough for me. Thanks again.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<html><head>
<style type="text/css">
 input &#123; border: 0px; background-color: #ffffff; color: blue; cursor: hand; &#125;
</style>
</heady><body>
<form method="POST">
	<input type="hidden" name="name" value="value"/>
	<input type="submit" name="whereToGo" value="Prev" />
	<input type="submit" name="whereToGo" value="-100" />
	<input type="submit" name="whereToGo" value="-10" />
	<input type="submit" name="whereToGo" value="-5" />
</form>
</body></html>
with the right css you wouldn't see any difference ;)
Post Reply