Solved

Passing html variables from the form using Radio buttons

Posted on 2004-04-18
5
773 Views
Last Modified: 2012-08-13
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(/=/,$pair);
$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


0
Comment
Question by:ronan_40060
  • 3
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 10855133
#!/usr/bin/perl

use CGI qw(:standard);

# Get Form Variables

my $type=param('passed_span');
my $param=param("passed_start");

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";
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10857489
Thanks Ozo
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('passed_start');
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+)[^:]+:\s*([^\n]+)/i) {
            print  "<b>Nombre XML</b>: $xml<br>\n<b>Nombre de PDF(xml)</b>: $x_pdf<br>\n<b>Pourcentage de réussite</b>:$x_reussite\n<br><br>";
         }
         if (my ($doc,  $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i) {
            print "<b>Nombre DOC</b>: $doc<br>\n<b>Nombre de PDF(doc)</b>: $d_pdf<br>\n<b>Pourcentage de réussite</b>:$d_reussite";
         }
         last;  
      }
      print "</td>";
      print "</tr>";
      close FILE;
      print "</table>";
      print "<tr height=\"5%\">";
      print "<td align = \"center\" colspan =\"2\" bgColor=\"#cd853f\">&nbsp;</td>";
      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

0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10859733
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
0
 
LVL 84

Expert Comment

by:ozo
ID: 10875678
I don't get any error there.
What error does it show you?
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10875940
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')."?START=".param(START));
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now