ronan_40060
asked on
Passing html variables from the form using Radio buttons
Here is my HTML script where user types the date in (YYYY-MM-DD) format and then he has 3 options
1> get the required o/p corresponding to that date
2> get the required o/p corresponding to the week in the specified date in the search criteria
3> get the required o/p for the month specified in search criteria
here is the HTML front end code
print <<HTML;
<CENTER>
<form name="webform" action="redirect.pl" method="POST">
<TABLE border=3 width=500 cellspacing=0 cellpadding=2 bgcolor="#C0C0C0">
<tr>
<TD>
Search Start Date:(YYYY/MM/DD)
</TD>
<TD>
<INPUT TYPE="TEXT" VALUE="" NAME="passed_start">
</TD>
</tr>
<tr>
<TD>
SEARCH:<br>select number of days-weeks or months
</TD>
<TD>
<HR>
<b>DAY</b><input type="radio" name="passed_span" value="day" CHECKED><br>
<b>WEEK</b><input type="radio" name="passed_span" value="week"><br>
<b>MONTH</b><input type="radio" name="passed_span" value="month">
</TD>
</tr>
<tr>
<td COLSPAN=2>
<INPUT NAME="Submit" TYPE="submit" VALUE="SUBMIT"> <INPUT NAME="reset" TYPE="reset" VALUE="Reset Form">
</td>
</tr>
</table>
</FORM>
HTML
print $query->end_html;
exit
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
here is my redirect.pl script
#!/usr/bin/perl
$|++;
# Get Form Variables
&parse_form;
$type=?????;
$trm = ??????;
$trm =~s//+/;
if ($type eq " "){
$url = "http://localhost/cgi-bin/resultone.pl";
$param = ????? ;
}
elsif ($type eq " " )
{
$url = "http://localhost/cgi-bin/resulttwo.pl";
$param = ??????;
}
elsif ( $type eq " ")
{
$url = "http://localhost/cgi-bin/resultthree.pl";
$param = ?????;
}
print "Location: http://$url?$param\n\n";
sub parse_form {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
($key,$value)=split(/=/,$p air);
$value= ~s/\+/ /g;
$value=~ s/%([a-fA-F0-9][a-fA-F0-9] )/pack("C" , hex($1))/eg;
$value=~s/~!/~!/g;
$value=~s/[\n\r]//sg;
$value=~s/\[\]//g;
$form{$key}=$value;
}
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
If user select radio button of day then he will be redirected to http://localhost/cgi-bin/resultone.pl
if he selects second radio button thats weeks , he will be redirected to http://localhost/cgi-bin/resulttwo.pl
and if he selects radio button of month , he will be redirected to http://localhost/cgi-bin/resultthree.pl
Now my question is How do I pass variable from frontend script in the redirect.pl so that we get the desired result
regards
1> get the required o/p corresponding to that date
2> get the required o/p corresponding to the week in the specified date in the search criteria
3> get the required o/p for the month specified in search criteria
here is the HTML front end code
print <<HTML;
<CENTER>
<form name="webform" action="redirect.pl" method="POST">
<TABLE border=3 width=500 cellspacing=0 cellpadding=2 bgcolor="#C0C0C0">
<tr>
<TD>
Search Start Date:(YYYY/MM/DD)
</TD>
<TD>
<INPUT TYPE="TEXT" VALUE="" NAME="passed_start">
</TD>
</tr>
<tr>
<TD>
SEARCH:<br>select number of days-weeks or months
</TD>
<TD>
<HR>
<b>DAY</b><input type="radio" name="passed_span" value="day" CHECKED><br>
<b>WEEK</b><input type="radio" name="passed_span" value="week"><br>
<b>MONTH</b><input type="radio" name="passed_span" value="month">
</TD>
</tr>
<tr>
<td COLSPAN=2>
<INPUT NAME="Submit" TYPE="submit" VALUE="SUBMIT"> <INPUT NAME="reset" TYPE="reset" VALUE="Reset Form">
</td>
</tr>
</table>
</FORM>
HTML
print $query->end_html;
exit
}
--------------------------
here is my redirect.pl script
#!/usr/bin/perl
$|++;
# Get Form Variables
&parse_form;
$type=?????;
$trm = ??????;
$trm =~s//+/;
if ($type eq " "){
$url = "http://localhost/cgi-bin/resultone.pl";
$param = ????? ;
}
elsif ($type eq " " )
{
$url = "http://localhost/cgi-bin/resulttwo.pl";
$param = ??????;
}
elsif ( $type eq " ")
{
$url = "http://localhost/cgi-bin/resultthree.pl";
$param = ?????;
}
print "Location: http://$url?$param\n\n";
sub parse_form {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
($key,$value)=split(/=/,$p
$value= ~s/\+/ /g;
$value=~ s/%([a-fA-F0-9][a-fA-F0-9]
$value=~s/~!/~!/g;
$value=~s/[\n\r]//sg;
$value=~s/\[\]//g;
$form{$key}=$value;
}
}
--------------------------
If user select radio button of day then he will be redirected to http://localhost/cgi-bin/resultone.pl
if he selects second radio button thats weeks , he will be redirected to http://localhost/cgi-bin/resulttwo.pl
and if he selects radio button of month , he will be redirected to http://localhost/cgi-bin/resultthree.pl
Now my question is How do I pass variable from frontend script in the redirect.pl so that we get the desired result
regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I modified redirect.pl script as
and now I modified it
as
use CGI qw(:standard);
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
# Get Form Variables
my $q=new CGI;
my $type= $q ->param('passed_span');
my $param= $q ->param('passed_start');
my $url;
if( $type eq "day" ){
$url = "http://localhost/cgi-bin/resultone.pl";
}elsif( $type eq "week" ){
$url = "http://localhost/cgi-bin/resulttwo.pl";
}elsif( $type eq "month" ){
$url = "http://localhost/cgi-bin/resultthree.pl";
}
print "Location: http://$url?$param\n\n";
my Perl builder tool shows me error at my $q=new CGI;
let me know what u think
and now I modified it
as
use CGI qw(:standard);
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
# Get Form Variables
my $q=new CGI;
my $type= $q ->param('passed_span');
my $param= $q ->param('passed_start');
my $url;
if( $type eq "day" ){
$url = "http://localhost/cgi-bin/resultone.pl";
}elsif( $type eq "week" ){
$url = "http://localhost/cgi-bin/resulttwo.pl";
}elsif( $type eq "month" ){
$url = "http://localhost/cgi-bin/resultthree.pl";
}
print "Location: http://$url?$param\n\n";
my Perl builder tool shows me error at my $q=new CGI;
let me know what u think
I don't get any error there.
What error does it show you?
What error does it show you?
ASKER
Ozo I got it working with your old script that you posted for one old question of redirection here is your script hich is working fine for me
print redirect('http://localhost/cgi-bin/'.(${{
day => 'resultone.pl',
week => 'resulttwo.pl',
month =>'resultthree.pl',
}}{param(PASSED)}||'common .pl')."?ST ART=".para m(START));
print redirect('http://localhost/cgi-bin/'.(${{
day => 'resultone.pl',
week => 'resulttwo.pl',
month =>'resultthree.pl',
}}{param(PASSED)}||'common
ASKER
Now here is my final scripts
1> Front End HTML script
print <<HTML;
<CENTER>
<form name="webform" action="redirect.pl" method="POST">
<TABLE border=3 width=500 cellspacing=0 cellpadding=2 bgcolor="#f5deb3">
<tr>
<TD>
<B>Search Start Date:(YYYY-MM-DD)</B> =>
</TD>
<TD>
<INPUT TYPE="TEXT" VALUE="" NAME="passed_start">
</TD>
</tr>
<tr>
<TD>
SEARCH:<br>select number of days-weeks or months
</TD>
<TD>
<HR>
<b>DAYS</b><input type="radio" name="passed_span" value="day" CHECKED><br>
<b>WEEKS</b><input type="radio" name="passed_span" value="week"><br>
<b>MONTHS</b><input type="radio" name="passed_span" value="month">
</TD>
</tr>
<tr>
<td COLSPAN=2>
<INPUT NAME="Submit" TYPE="submit" VALUE="SUBMIT"> <INPUT NAME="reset" TYPE="reset" VALUE="Reset Form">
</td>
</tr>
</table>
</FORM>
HTML
--------------------------
redirect.pl
use CGI qw(:standard);
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
# Get Form Variables
my $type=param('passed_span')
my $param=param("passed_start
my $url;
if( $type eq "day" ){
$url = "http://localhost/cgi-bin/resultone.pl";
}elsif( $type eq "week" ){
$url = "http://localhost/cgi-bin/resulttwo.pl";
}elsif( $type eq "month" ){
$url = "http://localhost/cgi-bin/resultthree.pl";
}
print "Location: http://$url?$param\n\n";
--------------------------
here is my resultone.pl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
my $monthName;
my $longdate=$q->param('passe
my($year, $month, $day) = split (/-/, $longdate);
$monthName = "Jan" if ($month == 1);
$monthName = "Feb" if ($month == 2);
$monthName = "Mar" if ($month == 3);
$monthName = "Apr" if ($month == 4);
$monthName = "May" if ($month == 5);
$monthName = "Jun" if ($month == 6);
$monthName = "Jul" if ($month == 7);
$monthName = "Aug" if ($month == 8);
$monthName = "Sep" if ($month == 9);
$monthName = "Oct" if ($month == 10);
$monthName = "Nov" if ($month == 11);
$monthName = "Dec" if ($month == 12);
my $date = $monthName." ".$day;
$/ = "GENERATION";
open FILE, "c:/generation.txt" or die $!;
print $q->header;
print "<html><body>";
print "<BODY leftmargin=0 topmargin=0>";
print "<table height=\"100%\" width = \"100%\" cellpadding = \"0\" cellspacing = \"0\" border = \"2\" align = \"center\">";
print "<tr height=\"5%\">";
print "<td align = \"center\" colspan =\"2\" bgColor=\"#cd853f\">";
print "<FONT face=\"Times New Roman\" size=\"5.5\"> Result </font>";
print "</td>";
print "</tr>";
print "<tr height=\"90%\">";
print "<td width = \"100%\" colspan = \"2\">";
print "<br>";
print"<br>";
print"<br>";
print "<br>";
print "<table align=\"center\" bgcolor=\"#f5deb3\" border=2 bordercolor=\"maroon\">";
print "<tr>";
print "<td>";
print " <b>Date Donnée : $date</b>";
print "<br>";
print "<br>";
while (<FILE>) {
next unless /$date/i;
if (my ($xml, $x_pdf, $x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+
print "<b>Nombre XML</b>: $xml<br>\n<b>Nombre de PDF(xml)</b>: $x_pdf<br>\n<b>Pourcentage
}
if (my ($doc, $d_pdf, $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+
print "<b>Nombre DOC</b>: $doc<br>\n<b>Nombre de PDF(doc)</b>: $d_pdf<br>\n<b>Pourcentage
}
last;
}
print "</td>";
print "</tr>";
close FILE;
print "</table>";
print "<tr height=\"5%\">";
print "<td align = \"center\" colspan =\"2\" bgColor=\"#cd853f\">
print "</tr>";
print "</table>";
print "</body></html>";
__________________________
Now in my HTML script
when I enter date like 2002-09-25 and press submit
the redirect.pl directs it to resultone.pl which should display the o/p of a given query
instead in displays a blank page
I dont know why
I am passing a variable from redirect.pl thats passed_start to resultone.pl
let me know whats wrong with the script
regards