StroudPete
ISP
Background first. I'm a (forms) vb.Net developer but come from a Unix background. I have a working knowledge of Perl, good enough to write a quite logically complex cgi script to do searches on flat file data for my website. I do not have a great deal of practical perl knowledge - just what I taught myself to build a few scripts (the search is several hundered lines). I can grasp the language constructs and code, but I don't properly understand the inter-relationships when moving between browser pages / scripts and browsers (again, enough to "get" info from my webpages and process, and to pass to new scripts - oh, and write html code, obviously).
I want to intiate a search on my phpbb board. Using the code from the built-in search page I have constructed a web page that simulates the phpbb search page, whilst looking like the rest of my site, and being understandable to non techie users. The data is sent via "POST". Because I' want to fiddle with the search terms the user enters, I'd like to send the data to a cgi script, fiddle with it and then initiate the php search.
The problem. I can initiate the search using the standard "GET" method of sending data, and the results are almost perfect. The only thing wrong is that I get the results listed by post rather than topic. When I use a "POST" method, the results are correct but not formatted with colours and there are no images (IE6) or the browser just lists the html code (Firefox 1.5). I haven't tried sending POST data before, and only scabbled together my script after a lot of googling - I don't really understand the concept enough to debug it.
The help I'm looking for! Since this isn't a phpbb board, I don't expect any help on making the GET script work perfectly, and since the phpbb html code uses POST, perhaps it can't be made to work 100%. Hence I'd like to know what I'm missing in the POST script - obviously I'm missing some vital code!
Here's the snippet of my html page which gives perfect results:
Here's my test cgi GET script (works except the show_results=topics parameter seems not to be processed) :
Here's my test cgi PUT script (works on all parameters, but IE6 shows page unformatted and no images (no "home"/"root"?) and Firefox just displays the html code):
Thanks for reading all this!
Pete Jones
I want to intiate a search on my phpbb board. Using the code from the built-in search page I have constructed a web page that simulates the phpbb search page, whilst looking like the rest of my site, and being understandable to non techie users. The data is sent via "POST". Because I' want to fiddle with the search terms the user enters, I'd like to send the data to a cgi script, fiddle with it and then initiate the php search.
The problem. I can initiate the search using the standard "GET" method of sending data, and the results are almost perfect. The only thing wrong is that I get the results listed by post rather than topic. When I use a "POST" method, the results are correct but not formatted with colours and there are no images (IE6) or the browser just lists the html code (Firefox 1.5). I haven't tried sending POST data before, and only scabbled together my script after a lot of googling - I don't really understand the concept enough to debug it.
The help I'm looking for! Since this isn't a phpbb board, I don't expect any help on making the GET script work perfectly, and since the phpbb html code uses POST, perhaps it can't be made to work 100%. Hence I'd like to know what I'm missing in the POST script - obviously I'm missing some vital code!
Here's the snippet of my html page which gives perfect results:
Code:
<form action="[URL unfurl="true"]http://ccgi.quaffersoffers.co.uk/QOforum/search.php?mode=results"[/URL] method="POST">
Find tasting notes containing
<input class="INPUT_TEXT" type="text" name="search_keywords" size="25">
<input class="BUTTON" type="submit" value="Search" onmouseover="this.className = 'BUTTON_MOUSEOVER'" onmouseout="this.className = 'BUTTON'">
<br />
with:
<input class="RADIO_BUTTON" type="radio" name="search_terms" value="all">
<b>all</b> of the words
<input class="RADIO_BUTTON" type="radio" name="search_terms" value="any" checked="checked">
<b>at least one</b> word
<!-- hidden FIXED VALUES -->
<!-- search ALL forums in all boards (we only have one board) -->
<input type="hidden" name="search_forum" value="-1">
<input type="hidden" name="search_cat" value="-1">
<!-- search topic title and message -->
<input type="hidden" name="search_fields" value="all">
<!-- sort by date & time descending -->
<input type="hidden" name="sort_by" value="0">
<input type="hidden" name="sort_dir" value="DESC">
<!-- results as TOPIC not post -->
<input type="hidden" name="show_results" value="topics">
<!-- return 200 characters -->
<input type="hidden" name="return_chars" value="200">
</form>
Here's my test cgi GET script (works except the show_results=topics parameter seems not to be processed) :
Code:
#!/usr/bin/perl --
use CGI;
use CGI qw /:standard/;
my $query = new CGI;
my $nextUrl = "[URL unfurl="true"]http://ccgi.quaffersoffers.co.uk/QOforum/search.php?";[/URL]
my $theParams = 'mode=results&search_keywords=chardonnay&show_results=topics&search_terms=any&search_forum=-1&search_cat=-1&search_fields=all&sort_by=0&sort_dir=DESC&return_chars=200';
print $query->redirect(-url => $nextUrl . "?" . $theParams);
Code:
#!/usr/bin/perl --
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
my $url = '[URL unfurl="true"]http://ccgi.quaffersoffers.co.uk/QOforum/search.php?mode=results';[/URL]
my $form = {
search_keywords => 'chardonnay',
search_terms => 'any',
search_forum => '-1',
search_cat => '-1',
search_fields => 'all',
sort_by => '0',
sort_dir => 'DESC',
show_results => 'topics'
};
my $response = $ua->request(POST $url, $form);
print "Content-type: text/plain\n\n";
print $response->is_success ? $response->content :
$response->error_as_HTML;
Pete Jones