CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Submit problems

 



yim11
Novice

Jul 26, 2000, 6:10 AM

Post #1 of 5 (729 views)
Submit problems Can't Post

Hello,
I am working with a perl program that has a Submit button for performing a search. The button is a image file, and works correctly as shown in the section of code below:
------------
print $query->image_button(-name=>'search',
-src=>'http://myserver.com/search.gif',
-border=>0);
------------
I would like to remove the image button, and use a regular Submit button, so that a user can simply hit 'Enter' to perform a search instead of physically having to click on the image. I have tried the following code:
-----------
print $query ->submit (-name=> 'search',
-value=>'Submit');
-----------
which ~appears~ to work fine, but never returns any results.
Can anyone shed some light on this for me?

TIA for any and all help!
-Jim


gawen
Deleted

Jul 27, 2000, 8:24 AM

Post #2 of 5 (729 views)
Re: Submit problems [In reply to] Can't Post

can you post the form printing code?


yim11
Novice

Jul 27, 2000, 8:40 AM

Post #3 of 5 (729 views)
Re: Submit problems [In reply to] Can't Post

Here it is, some of the names have been changed to protect the innocent Smile
!THANKS! in advance for all your help.
-Jim

------Begin Code--------------
#!/usr/bin/perl

use DBI;
use CGI;
use CGI qw(:all);
use CGI::Carp qw (fatalsToBrowser confess);

my $query = new CGI;
$user = $query-> cookie('login');
$password = $query-> cookie('pass');

$dbname="pde";
$dbh=DBI->connect("dbi:Pg:dbname=$dbname",$user,$password) | | sendto_main();

if ( param('search.x') ) {

# L I S T I N G

print $query->header;
print $query ->start_html
(
-title=> 'PDE Comments Advanced Queries Page',
-BGCOLOR=>'white',
-TEXT=>'black',
-LINK=>'blue',
-VLINK=>'blue',
-ALINK=>'blue'
);
$searchs=$query->param('searchs');

$statement="select *,oid from comments where subject like '%$searchs%' or catno like '%$searchs%' or contents like '%$searchs%'";
# On is 0 for no parameters 1 for paramters already chosen

$statement="$statement ORDER BY catno desc, sent desc";
$sth = $dbh->prepare("$statement");
$rv= $sth->execute( );
my %dat;
print $query ->startform(-method=>"POST",
-action=>"http://myserver.com/cgi-bin/plain_comments1.pl");
print "<left>\n";
print $query->textfield(-name=>'searchs',
-maxlength=>100,
-size=>50);

print $query->image_button(-name=>'search',
-src=>'http://myserver.com/search.gif',
-border=>0);

print $query->a({href=>'http://myserver.com/search.html'},' Help '),' ';
print $query->a({-href=>'http://myserver.com/cgi-bin/advanced_comments.pl'},'Advanced');
print "</left>";

print <<"ENDPRINT";

<center><table WIDTH="100%">
<tr>
<td WIDTH="10"></td>
<td WIDTH="120"><left><font size=3 color="blue"><B><u>Cat. No.</u></b></font></left></td>
<td WIDTH="120"><left><font size=3 color="blue"><B><u>Date</u></b></font></left></td>
<td WIDTH="400"><left><font size=3 color="blue"><B><u>Message Subject</u></b></font></left></td>
<td WIDTH="200"><left><font size=3 color="blue"><B><u>From</u></b></font></left></td>
<td WIDTH="200"><left><font size=3 color="blue"><B><u>To</u></b></font></left></td>
</tr>
ENDPRINT

while ($dat = $sth->fetchrow_hashref) {
print "
<tr>
<td nowrap WIDTH=\"10\"><input TYPE=image NAME=\"$dat->{oid}\" src=\"http://myserver.com/datalist.gif\" border=0></td>
<td nowrap WIDTH=\"120\"><left> $dat->{catno} </left></td>
<td nowrap WIDTH=\"120\"><left> $dat->{sent} </left></td>
<td nowrap WIDTH=\"400\"><left> $dat->{subject} </left></td>
<td nowrap WIDTH=\"200\"><left> $dat->{whofrom} </left></td>
<td nowrap WIDTH=\"200\"><left> $dat->{sendto} </left></td></tr>
";
}
print "</table>";
print $query->end_form;
print $query -> end_html();

} elsif ( param() ) {

# D o c u m e n t s
# If the parameter is an oid (i.e. if submit not sent but a param was
# then we get the fields from the database for that oid and send that
# request all the data for that information so that we can obtain all multiple
# row comments.

print $query->header;
print $query ->start_html
(
-title=> 'PDE Comments Advanced Queries Page',
-BGCOLOR=>'white',
-TEXT=>'black',
-LINK=>'blue',
-VLINK=>'blue',
-ALINK=>'blue'
);
@par=$query->param();
$oids=$par[1];
chop($oids);
chop($oids);
$sth = $dbh->prepare("select * from comments where oid=$oids");
$rv = $sth->execute( );
my %dat;
while ($dat = $sth->fetchrow_hashref) {
# Fetch the data belonging to that oid and translate it for the full
# select.
$sth1 = $dbh->prepare("select * from comments where catno='$dat->{catno}' AND sent='$dat->{sent}' AND subject='$dat->{subject}' AND whofrom='$dat->{whofrom}' AND sendto='$dat->{sendto}' order by bin");
$rv1 = $sth1->execute( );
my %data;
$i=0;
while ($data = $sth1->fetchrow_hashref) {
if ($i==0) {
$cc=$data->{cc};
$cc=~s',', 'g;
$help=$query -> a({-href=>'http://myserver.com/Address_Help.html', -target=>'_new'},'Help');
$sub_table=$query -> table({-border=>0,-width=>'600'},
Tr({-align=>LEFT, -valign=>TOP},
[
td(['Catno:',$data->{catno}]),
td(['Date:',$data->{sent}]),
td(['To:',$data->{sendto}]),
td(['Cc:',$cc]),
td(['From:',$data->{whofrom}]),
td(['Subject:',$data->{subject}]),
]
)
);
$applet_ref="<applet code=PDEMail width=624 height=168 id=applet codebase=java>\n
<param name=\"subject\" value=\"$data->{subject}\">\n
<param name=\"from\" value=\"$data->{whofrom}\">\n<param name=\"catno\" value=\"$data->{catno}\">\n
<param name=\"date\" value=\"$data->{sent}\">\n<param name=\"to\" value=\"$data->{sendto}\">\n
<param name=\"cc\" value=\"$data->{cc}\">\n<param name=\"login\" value=\"$user\">\n</applet>";
print $query -> table({-border=>0,-width=>'624'},
Tr({-align=>LEFT, -valign=>TOP},
[
td([$applet_ref]),
td({-align=>RIGHT},[$help]),
td([$sub_table])
]
)
);
}
$contents=$data->{contents};
@ArrayofChars=split('',$contents);
$n_elements=@ArrayofChars;
for ($xx=0;$xx<$n_elements;$xx++) {
if ($xx==0 &#0124; &#0124; ( ($ArrayofChars[$xx-1] eq "\n") && ($ArrayofChars[$xx] eq "\n") )&#0124; &#0124; ( ($ArrayofChars[$xx-1] eq "\n") && ($ArrayofChars[$xx+1] eq "\n") )){
$ArrayofChars[$xx]="<P>";
}
}
$" = "";
print "\n@ArrayofChars";
$i=1;
}
break;
}
print $query -> end_html;

} else {

# F O R M
# This section creates the form for processing by the rest of the program
print $query->header;
print $query ->start_html
(
-title=> 'PDE Comments Advanced Queries Page',
-BGCOLOR=>'white',
-TEXT=>'black',
-LINK=>'blue',
-VLINK=>'blue',
-ALINK=>'blue'
);
print $query ->startform(-method=>"POST",
-action=>"http://myserver.com/cgi-bin/plain_comments1.pl");
print "<left>\n";
print $query->textfield(-name=>'searchs',
-value=>$searchs,
-maxlength=>100,
-size=>50);

print $query->image_button(-name=>'search',
-src=>'http://myserver.com/search.gif',
-border=>0);

print $query->a({href=>'http://myserver.com/search.html'},'Help'),' ';
print $query->a({-href=>'http://myserver.com/cgi-bin/advanced_comments.pl'},'Advanced');
print "</left>";
print "<center>";
#
# Access the database asking for an unique list of commentators
#
$sth = $dbh->prepare("select *,oid from comments where sent >('today'::date - '2 days'::timespan)::date and bin=0 order by sent desc limit 50");
$rv= $sth->execute( );
my %dat;

print <<"ENDPRINT";

<center><table WIDTH="100%">
<tr>
<td WIDTH="10"></td>
<td WIDTH="120"><left><font size=3 color="blue"><B><u>Cat. No.</u></b></font></left></td>
<td WIDTH="120"><left><font size=3 color="blue"><B><u>Date</u></b></font></left></td>
<td WIDTH="400"><left><font size=3 color="blue"><B><u>Message Subject</u></b></font></left></td>
<td WIDTH="200"><left><font size=3 color="blue"><B><u>From</u></b></font></left></td>
<td WIDTH="200"><left><font size=3 color="blue"><B><u>To</u></b></font></left></td>
</tr>
ENDPRINT

while ($dat = $sth->fetchrow_hashref) {
print "
<tr>
<td nowrap WIDTH=\"10\"><input TYPE=image NAME=\"$dat->{oid}\" src=\"http://myserver.com/datalist.gif\" border=0></td>
<td nowrap WIDTH=\"120\"><left> $dat->{catno} </left></td>
<td nowrap WIDTH=\"120\"><left> $dat->{sent} </left></td>
<td nowrap WIDTH=\"400\"><left> $dat->{subject} </left></td>
<td nowrap WIDTH=\"200\"><left> $dat->{whofrom} </left></td>
<td nowrap WIDTH=\"200\"><left> $dat->{sendto} </left></td></tr>
";
}
print "</table>";

# Set up the Parts of the Table

print $query-> end_form;
print $query -> end_html();
}

# Sub Routines Belong HERE!

sub sendto_main { # Pushes Illegal access to the main page for login
print $query->header(-Refresh=>'0; URL=http://myserver.com/cgi-bin/main.cgi');
print $query ->start_html();
print $query -> end_html;
exit;
}

sub check_permissions {
my ($user, $passwd, $page)=@_;
my $dbname = "www";
my $dbh1 = DBI->connect("dbi:Pg:dbname=$dbname",$user,$passwd);
my $sth1 = $dbh1->prepare("select $page from permissions where username='$user'");
my $rv1 = $sth1->execute( );
}
-----------End Code---------------


gawen
Deleted

Jul 28, 2000, 7:31 AM

Post #4 of 5 (729 views)
Re: Submit problems [In reply to] Can't Post

presuming that your code works (i couldn't no errors) you just have to substitute the code that prints the image button for :

"print $query->submit('button_name','value');"

it should work this way...


yim11
Novice

Jul 28, 2000, 12:45 PM

Post #5 of 5 (729 views)
Re: Submit problems [In reply to] Can't Post

Thanks!
I tried, but no luck. Everything I try seems to work OK, but nothing produces search results (or errors).... except using the button_image. I can't understand what is wrong with my script were I can't eliminate that graphic and still have the same functionality. Actually, the boss sayz that as long I can get the 'Enter' key to search (i.e. user inputs search string, hits 'Enter' - results displayed) then its good to go, so I assumed that eliminating the graphic and replacing it with a submit button was the logical solution....

Back to the drawing board I guess....
THANKS for all your help!
-Jim

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives