Gossamer Forum
Home : Products : DBMan : Customization :

Link to previous search page

Quote Reply
Link to previous search page
Hello there,

I've almost finished my customization of DBMan, thanks to the help provided here by most of you, especially JPDeni and Alex !

But I would like to have on each page containing the set of matching records returned by a search one link to this search page, so ones can come back and just modify the previously used search criteria.

At first, I was thinking to use the <input type=button onClick.backward(-n)> but how to calculate the correct value for -n. One user may go back and forth on already displayed pages before to decide to go back to the search menu.

The html_search_failure subroutine displays the last used search criteria. But how to access it if the search was successful ?

Any other trick ?

Thanks in advance for your help !

Cheers,
Germain
Quote Reply
Re: Link to previous search page In reply to
You'll need to get a list of the search terms used in the previous search.

In case there are things like spaces and other non-alphanumeric characters in the search terms, you'll need to encode the search terms. Add the following subroutine to db.cgi:

Code:
sub urlencode {
# --------------------------------------------------------
my($toencode) = @_;
$toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode=~s/\%2F/\//g;
return $toencode;
}

Then make a list of the search terms. This would be in html_view_success, before &html_footer, but not within a print statement.

Code:
foreach $column (@db_cols) {
if ($in{$column}) {
$in{$column} = &urlencode($in{$column});
$list .= "&$column=$in{$column}";
}
}
print qq|<a href="$db_script_link_url$list&view_search=1">Modify Search</a>|;

In html_view_search, change

&html_record_form();

to

&html_record_form(%in);

This is untested, but it seems like it would work.


------------------
JPD


[This message has been edited by JPDeni (edited May 31, 1999).]
Quote Reply
Re: Link to previous search page In reply to
Thanks a lot Carol !

No suspense, it works as expected ! And you answered so rapidly ! What can I say more ?

Well, a small thing: I have tried to replace the <a href.. link by a submit button without success ! My browser's address field contains exactly the same string as the one returned by the link but I get an empty form each time... What am I missing ?

Germain

PS: Surely I will need to read completely my "Perl for the dummies" book one of those days, to prolungate my keyboard's life by minimizing all those script modifications...

Quote Reply
Re: Link to previous search page In reply to
Thanks so much for letting me know. I'm always a little nervous when I give somebody code I haven't tested. Smile

I don't know why your submit button wouldn't work. Unless you need to have all of the elements in a form. This is getting more into CGI than Perl, though, and I'm more comfortable with Perl.

I really like the "Perl for Dummies" book, in addition to the O'Reilley books. I find that sometimes I don't understand a concept that one explains, but when I read a completely different perspective, it helps a lot.


------------------
JPD





Quote Reply
Re: Link to previous search page In reply to
So if any of you (boys, girls, robots, aliens, etc.) has any suggestion to solve the above problem, please share it here...

Cheers,
Germain
Quote Reply
Re: Link to previous search page In reply to
If you wanted to use a submit button, you could probably create a whole form with hidden fields. You also wouldn't need to encode the values, since they are encoded automatically if they're in a form.

Code:
print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;
foreach $column (@db_cols) {
if ($in{$column}) {
print qq|<input type="hidden" name="$column" value="$in{$column}">\n|;
}
}
print qq|
<INPUT TYPE="SUBMIT" NAME="view_search" VALUE="Modify Search">
</form>
|;

Leave the &html_record_form(%in); line in html_view_search.

------------------
JPD





Quote Reply
Re: Link to previous search page In reply to
Bravo Carol, you did it again !

I've implemented your code last night and it works beautifully.

Many thanks again to the Godess of Perl and to the pEarl Grey of Godesses (don't choose, you are entitled to both) !

Geetings from SwitzerLANd,
Germain
Quote Reply
Re: Link to previous search page In reply to
LOL!!! I just got up this morning. What a nice way to start the day!


------------------
JPD