Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2004
    Posts
    21

    Unanswered: read file in option

    If file.txt contain
    Oreo
    Oatmeal
    Chocolate

    what change in code below I need to make to use file.txt file instead of hard coding my options
    If CGI is involved could you please show me the codes.

    <FORM METHOD=GET ACTION=cgi-bin/foo>

    Pick your favorite:
    <SELECT Name="cookie">
    <OPTION>Oreo
    <OPTION>Oatmeal
    <OPTION>Chocolate
    </SELECT>
    <INPUT TYPE=SUBMIT VALUE=Submit>

    </FORM>

  2. #2
    Join Date
    Jun 2004
    Posts
    21
    Any one can help?

  3. #3
    Join Date
    Jun 2004
    Posts
    21
    I need help on this, some one please help

  4. #4
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    What you're after is marked by "# ====="
    Code:
    #!/usr/bin/perl
    
    use strict;
    use CGI qw/:standard :html3/;
    use CGI::Carp;
    
      my(@a_Parameters)=qw(name flavor scoops);
      my($o_cgi)=CGI->new();
      my(@a_Actual)=$o_cgi->param();
      unless (Matches(\@a_Parameters,\@a_Actual)) { # either no parameters or one or more invalid parameter(s) was passed
        # =====
        open (FLAVORS,'<flavors.txt') or die "$!";
        my(@a_Flavors)=<FLAVORS>; chomp(@a_Flavors);
        close (FLAVORS);
        # =====
        print $o_cgi->header(),
           $o_cgi->start_html("Ice Cream Stand"),
           $o_cgi->h1("Ice Cream Stand"),
           $o_cgi->hr(),
           $o_cgi->start_form(),
           $o_cgi->p("Name?",$o_cgi->textfield("name")),
           #                                                                 ==========
           $o_cgi->p("Flavor?",$o_cgi->popup_menu("flavor",\@a_Flavors)),
           $o_cgi->p("Scoops?",$o_cgi->popup_menu("scoops",[1..3])),
           $o_cgi->p($o_cgi->submit("order"),$o_cgi->reset("clear")),
           $o_cgi->end_form(),
           $o_cgi->hr(),
           $o_cgi->end_html;
         } else { # only valid parameters were passed
        my($name)=$o_cgi->param("name");
        my($flavor)=$o_cgi->param("flavor");
        my($scoops)=$o_cgi->param("scoops");
        print $o_cgi->header(),
           $o_cgi->start_html("Ice Cream Stand"),
           $o_cgi->h1("Ice Cream Stand"),
           $o_cgi->p("Okay,",$o_cgi->param("name"),$o_cgi->param("flavor"),$o_cgi->param("scoops")),
           $o_cgi->end_html();
         };
    
      sub Matches {
        my($ra_Expected,$ra_Actual)=@_;
        my(%h);
        @h{@$ra_Expected}=();
        delete @h{@$ra_Actual} if (defined($ra_Actual));
        return (keys %h == 0) ? 1 : 0;
         };

  5. #5
    Join Date
    Jun 2004
    Posts
    21
    Thank you for your reply and codes; I do not understand how it works
    Could you please explain?

  6. #6
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Since you're in the Perl & DBI forum, I have to assume that a Perl solution is acceptable, so

    Code:
    #!/usr/bin/perl -w
    
    use strict;
    use CGI qw/:standard :html3/;
    use CGI::Carp;
    
      my($o_cgi)=CGI->new();
      # Open a form with the proper headers
      print $o_cgi->header(),
        $o_cgi->start_html('Window Header'), # This is the window header
        $o_cgi->h1('H1 Header'),             # This is an H1 header
        $o_cgi->start_form();
    
      # Read the list of cookies from "file.txt"
      open (COOKIES,'<file.txt') or die "$!";
      my(@a_Cookies)=<COOKIES>; chomp(@a_Cookies);
      close (COOKIES);  
      # Create a drop down list using the list of cookies
      print $o_cgi->p('Pick your favorite:',$o_cgi->popup_menu('cookie',\@a_Cookies)),
        $o_cgi->p($o_cgi->submit('submit'));
    
      # Close the form and send it to server
      print $o_cgi->end_form(),
        $o_cgi->end_html;

  7. #7
    Join Date
    Jun 2004
    Posts
    21
    Thank you so much for your reply and codes working fine as it is.

    Previously I was using the following HTML to do data entry in my customer field or "Cust Name"(c_name).
    Now I am not quit sure how do I use or fit your codes with below HTML codes
    Could you please show me how to?


    <FORM METHOD="post" >
    <TABLE>
    <TR>
    <TD>Cust Name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="c_name"></TD>
    </TR>
    <TR>
    <TD>Manager Email: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="email"></TD>
    </TR>
    <TR>
    <TD>Manager name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="m_Name"></TD>
    </TR>
    <TR>
    <td colspan="3">
    Select Operating System:<BR>
    <INPUT TYPE="radio" NAME="os" value="linux" > LINUX</input><BR>
    <INPUT TYPE="radio" NAME="os" value="hp" > HP</input><BR>
    <INPUT TYPE="radio" NAME="os" value="sun" > SUN</input><BR>
    </td>
    </TR>
    <TR>
    <TD><INPUT TYPE="RESET" VALUE="Clear Form"></TD>
    <TD><INPUT TYPE="submit" name="submit" VALUE="Clear calendar File"></TD>
    <TD><INPUT TYPE="SUBMIT" name="submit" VALUE="Submit Calendar" ></TD>
    </TR>
    </TABLE>
    </FORM>

    <HR>
    <FORM METHOD="post" >
    Pick Your Program To Run:
    <SELECT Name="cookie" SIZE=3>
    <OPTION VALUE="1">Hello.pl
    <OPTION VALUE="2">Goodby.pl
    <OPTION VALUE="3">Program.pl
    </SELECT>
    <INPUT TYPE=SUBMIT VALUE=Submit>
    </FORM>

  8. #8
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Your code looks like

    Code:
    <FORM METHOD="post" >
    <TABLE>
    <TR>
    <TD>Cust Name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="c_name"></TD>
    </TR>
    <TR>
    <TD>Manager Email: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="email"></TD>
    </TR>
    <TR>
    <TD>Manager name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="m_Name"></TD>
    </TR>
    <TR>
    <td colspan="3">
    Select Operating System:<BR>
    <INPUT TYPE="radio" NAME="os" value="linux" > LINUX</input><BR>
    <INPUT TYPE="radio" NAME="os" value="hp" > HP</input><BR>
    <INPUT TYPE="radio" NAME="os" value="sun" > SUN</input><BR>
    </td>
    </TR>
    <TR>
    <TD><INPUT TYPE="RESET" VALUE="Clear Form"></TD>
    <TD><INPUT TYPE="submit" name="submit" VALUE="Clear calendar File"></TD>
    <TD><INPUT TYPE="SUBMIT" name="submit" VALUE="Submit Calendar" ></TD>
    </TR>
    </TABLE>
    </FORM>
    <HR>
    <FORM METHOD="post" >
    Pick Your Program To Run:
    <SELECT Name="cookie" SIZE=3>
    <OPTION VALUE="1">Hello.pl
    <OPTION VALUE="2">Goodby.pl
    <OPTION VALUE="3">Program.pl
    </SELECT>
    <INPUT TYPE=SUBMIT VALUE=Submit>
    </FORM>
    and translates roughly to the following CGI code
    Code:
    #!/usr/bin/perl -wT
    
    use strict;
    use CGI qw();
    
    my($o_CGI)=CGI->new();
    print $o_CGI->header()
       ,$o_CGI->start_html('Example')
       ,$o_CGI->h1('Example')
       ,$o_CGI->hr()
       ;
    
    my(%h_OS)=(linux=>"LINUX",hp=>"HP",sun=>"SUN");
    print $o_CGI->start_form() # Change "-border=>5" to "-border=>0" to make the border disappear
       ,$o_CGI->table({-border=>5},$o_CGI->Tr($o_CGI->td(["Cust Name:",$o_CGI->textfield(-name=>'c_name')]))
                                  ,$o_CGI->Tr($o_CGI->td(["Manager Email:",$o_CGI->textfield(-name=>'email')]))
                                  ,$o_CGI->Tr($o_CGI->td(["Manager Name:",$o_CGI->textfield(-name=>'m_name')]))
                                  ,$o_CGI->Tr($o_CGI->td(["Select Operating System:".$o_CGI->br().$o_CGI->radio_group(-name=>"os",-values=>[keys %h_OS],-labels=>\%h_OS,-linebreak=>1)]))
                                  ,$o_CGI->Tr($o_CGI->td([$o_CGI->reset(-value=>"Clear Form"),$o_CGI->submit(-value=>"Clear calendar file"),$o_CGI->submit(-value=>"Submit calendar")])))
       ,$o_CGI->end_form()
       ,$o_CGI->hr()
       ;
    
    my(%h_Programs)=(1=>"Hello.pl",2=>"Goodbye.pl",3=>"Program.pl");
    print $o_CGI->start_form()
       ,$o_CGI->p("Pick your program to run:",$o_CGI->scrolling_list(-NAME=>"cookies",-VALUES=>[keys %h_Programs],-LABELS=>\%h_Programs,-SIZE=>3,-MULTIPLE=>0),$o_CGI->submit("Submit"))
       ,$o_CGI->end_form()
       ;
    print $o_CGI->end_html
       ;
    Replace the line
    "my(%h_Programs)=(1=>"Hello.pl",2=>"Goodbye.pl",3= >"Program.pl");"
    with the correct code if you need to read a file of "cookies" in to populate the scrolling list
    Last edited by senza_nome; 07-05-04 at 18:29.

  9. #9
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Of course, you might prefer something that doesn't use CGI.pm (which I've used here only only in opening and closing

    Code:
    #!/usr/bin/perl -wT
    
    use strict;
    use CGI qw();
    
      open (COOKIES,'<cookie.txt') or die "$!";
      my(@a_Cookies)=<COOKIES>; chomp(@a_Cookies);
      close (COOKIES);
      my($size)=scalar @a_Cookies;
    
      my($o_CGI)=CGI->new();
      print $o_CGI->header()
         ,$o_CGI->start_html('Example')
         ,$o_CGI->h1('Example')
         ;
    
      #   Your original code:
      print <<END_OF_EXTRACT_A;
    <FORM METHOD="post" >
    <TABLE>
    <TR>
    <TD>Cust Name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="c_name"></TD>
    </TR>
    <TR>
    <TD>Manager Email: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="email"></TD>
    </TR>
    <TR>
    <TD>Manager name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="m_Name"></TD>
    </TR>
    <TR>
    <td colspan="3">
    Select Operating System:<BR>
    <INPUT TYPE="radio" NAME="os" value="linux" > LINUX</input><BR>
    <INPUT TYPE="radio" NAME="os" value="hp" > HP</input><BR>
    <INPUT TYPE="radio" NAME="os" value="sun" > SUN</input><BR>
    </td>
    </TR>
    <TR>
    <TD><INPUT TYPE="RESET" VALUE="Clear Form"></TD>
    <TD><INPUT TYPE="submit" name="submit" VALUE="Clear calendar File"></TD>
    <TD><INPUT TYPE="SUBMIT" name="submit" VALUE="Submit Calendar" ></TD>
    </TR>
    </TABLE>
    </FORM>
    <HR>
    <FORM METHOD="post" >
    Pick Your Program To Run:
    <SELECT Name="cookie" SIZE=".$size.">"
    END_OF_EXTRACT_A
    
      foreach (1..scalar @a_Cookies) {
        print "<OPTION VALUE=\"$_\">$a_Cookies[$_-1]";
         };
    
      print <<END_OF_EXTRACT_B;
    </SELECT>
    <INPUT TYPE=SUBMIT VALUE=Submit>
    </FORM>
    END_OF_EXTRACT_B
    
      print $o_CGI->end_html
         ;

  10. #10
    Join Date
    Jun 2004
    Posts
    21
    Hi,
    Sorry but I do not want make any chages in
    <FORM METHOD="post" >
    Pick Your Program To Run:
    <SELECT Name="cookie" SIZE=3>
    <OPTION VALUE="1">Hello.pl
    <OPTION VALUE="2">Goodby.pl
    <OPTION VALUE="3">Program.pl
    </SELECT>
    <INPUT TYPE=SUBMIT VALUE=Submit>
    </FORM>

    I want make change in html form code where is
    <TD>Cust Name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="c_name"></TD>
    </TR>
    Above is where I want to pick up list of my customer_names just with selection then continue with html form, then when I click submit run write_2_file.pl to write the data in a text file.

    <FORM METHOD="post" action="cgi-bin/write_2_file.pl">
    <TABLE>
    <TR>
    <TD>Cust Name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="c_name"></TD>
    </TR>
    <TR>
    <TD>Manager Email: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="email"></TD>
    </TR>
    <TR>
    <TD>Manager name: </TD>
    <TD colspan="2"><INPUT TYPE="TEXT" NAME="m_Name"></TD>
    </TR>
    <TR>
    <td colspan="3">
    Select Operating System:<BR>
    <INPUT TYPE="radio" NAME="os" value="linux" > LINUX</input><BR>
    <INPUT TYPE="radio" NAME="os" value="hp" > HP</input><BR>
    <INPUT TYPE="radio" NAME="os" value="sun" > SUN</input><BR>
    </td>
    </TR>
    <TR>
    <TD><INPUT TYPE="RESET" VALUE="Clear Form"></TD>
    <TD><INPUT TYPE="submit" name="submit" VALUE="Clear calendar File"></TD>
    <TD><INPUT TYPE="SUBMIT" name="submit" VALUE="Submit Calendar" ></TD>
    </TR>
    </TABLE>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •