Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Feb 2004
    Posts
    25

    Unanswered: Update file and run program

    Could you please help
    Using code below I want to be able to select The Os and enter Info below then by pressing button "Submit Calendar" to write Info to the first line of file in c:\tmp\calendar.txt
    For Example
    If HP is selected and Cust Name is ORANG and Manager Email is mangeorage@bla.com and Manager name is JOHN NUM press button "Submit Calendar "
    Then
    If LINUX is selected and Cust Name is CHIPS and Manager Email is mangechips@bla.com and Manager name is DICK TEE press button "Submit Calendar
    The calendar file will be
    ORANG HP mangeorage@bla.com JOHN NUM
    CHIPS LINUX mangechips@bla.com DICK TEE
    Note If button “Clear calendar File” is pressed it will clear the calendar.txt file.

    When calendar.txt file is completed I want to select my program hello.pl to run


    <FORM METHOD="GET" >
    <TABLE><TR>
    <TD>Cust Name: </TD>
    <TD><INPUT TYPE="TEXT" NAME="Name"></TD>
    </TR><TR>
    <TD>Manager Email: </TD>
    <TD><INPUT TYPE="TEXT" NAME="Name"></TD>
    </TR><TR>
    <TD>Manager name: </TD>
    <TD><INPUT TYPE="TEXT" NAME="Name"></TD>
    </TR><TR>

    Select Operating System:<BR>
    <INPUT TYPE=CHECKBOX NAME=LINUX >
    LINUX<BR>
    <INPUT TYPE=CHECKBOX NAME=HP >
    HP<BR>
    <INPUT TYPE=CHECKBOX NAME=SUN >
    SUN<BR>
    <HR>
    </TR><TR>
    <TD><INPUT TYPE="RESET" VALUE="Clear Form"></TD>
    <TD><INPUT TYPE="RESET" VALUE="Clear calendar File"></TD>
    <TD><INPUT TYPE="SUBMIT" VALUE="Submit Calendar" ></TD>
    </TR></TABLE>
    </FORM>

    <HR>
    <FORM METHOD=GET >
    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>

  2. #2
    Join Date
    Feb 2004
    Posts
    25
    Any one can help!

  3. #3
    Join Date
    Feb 2004
    Posts
    25
    Any one can help on this questin ??

  4. #4
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Try this one:

    the html-form:
    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>
    The cgi-skript:
    Code:
    #! /usr/bin/perl
    
    use CGI;
    use strict;
    use CGI::Carp qw(fatalsToBrowser);
    use warnings;
    
    my $cgi = CGI->new();
    print $cgi->header(-type='text/html');
    my %params = $cgi->Vars();
    
    my $cal_file = '/path/to/calendar_file.txt';
    
    if($params{submit} eq 'Clear calendar File'){
      open(W_CA,">$cal_file") or die $!;
      close W_CA;
      print "all entries in ",$cal_file," are deleted";
      exit(0);
    }
    
    open(W_CAL,">>$cal_file") or die $!;
    print W_CAL $params{c_name}," ",$params{os}," ",$params{email}," ",$params{m_name},"\n";
    close W_CAL;
    
    print qq~
    $params{c_name} $params{os} $params{email} $params{m_name} was submitted<br />
    ~;
    board.perl-community.de - The German Perl-Community

  5. #5
    Join Date
    Feb 2004
    Posts
    25
    I am not quit sur how this is working? or what do I need todo

    the html code does it save the data? if yes where to
    the cgi script refers to $cal_file = '/path/to/calendar_file.txt' I do not know when this file was created.

    this is what I have done save the html code then open in my browser using
    http://localhost/form.html

  6. #6
    Join Date
    Feb 2004
    Posts
    25
    renee,
    In the first of the my question (THE HTML) I want to know how I can I input the fields in a text file.

  7. #7
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    HTML can't save anything. HTML is just a document description language. It just provides the fields, where the user can type in the requested information. The data are saved by the cgi-script.

    You have to save the HTML-form in a HTML-file onto your server, where the other HTML-files are located. Put the cgi-script into the cgi-bin directory.

    I've just seen that there is still a mistake in my HTML-form. It has to be
    Code:
    <FORM METHOD="post" action="./cgi-bin/the_cgi_script.cgi">
    The path of action has to show on the cgi-script!

    You have mentioned to save the information in a .txt-file. You have to tell the cgi-script, where this file is located. That's what $cal_file stands for. So replace the path I have set by the path to the .txt-file on your server!
    board.perl-community.de - The German Perl-Community

  8. #8
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Quote Originally Posted by lonaj
    renee,
    In the first of the my question (THE HTML) I want to know how I can I input the fields in a text file.
    The information the user has typed in are in a "Query_STRING". In the cgi-script this QUERY_STRING is parsed in the line
    Code:
    my %params = $cgi->Vars()
    And the information are saved into the txt file in the line
    Code:
    print W_CAL [...];
    !
    board.perl-community.de - The German Perl-Community

  9. #9
    Join Date
    Feb 2004
    Posts
    25
    Ok thankx for info
    I have changed the path from
    my $cal_file = '/path/to/calendar_file.txt';
    to
    my $cal_file = 'c:\\uu\\calendar_file.txt';

    and when I run I get
    Can't modify negation (-) in scalar assignment at C:/Program Files/Apache Group/Apache2/cgi-bin/prog.cgi line 9, near "'text/html')"
    syntax error at C:/Program Files/Apache Group/Apache2/cgi-bin/prog.cgi line 23, near "",$params{m_name},"\"
    Can't find string terminator '"' anywhere before EOF at C:/Program Files/Apache Group/Apache2/cgi-bin/prog.cgi line 23.

  10. #10
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Ok, some mistakes happens while coding:

    Code:
    print $cgi->header(-type='text/html');
    ==>
    Code:
    print $cgi->header(-type => 'text/html');
    syntax error at C:/Program Files/Apache Group/Apache2/cgi-bin/prog.cgi line 23, near "",$params{m_name},"\"
    Can't find string terminator '"' anywhere before EOF at C:/Program Files/Apache Group/Apache2/cgi-bin/prog.cgi line 23.
    "\" has to be "\n"!
    board.perl-community.de - The German Perl-Community

  11. #11
    Join Date
    Feb 2004
    Posts
    25
    Yes Thank you all working ok.

  12. #12
    Join Date
    Feb 2004
    Posts
    25
    As perl original question and answer from Reneeb how do I modify the script or program to be able to read a customer file and select a customer name in solution by reneeb,

  13. #13
    Join Date
    Feb 2004
    Posts
    25
    Please some one help I need to know
    what changes i need to make in reneeb solution if I want to make selection in customer field and then continue with the solution provided.

    <FORM METHOD="post" action="/cgi-bin/the_cgi_script.cgi">
    <TABLE>
    <SELECT
    <option value="cust_1"<cust_1
    <option value="cust_1"<cust_2
    <option value="cust_3"<cust_3
    </SELECT>
    <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>
    ...
    ...


    if this is not correct where about in html-form I need to change.

    or
    is it possible to read a customer file instead of hard coding as above ?

  14. #14
    Join Date
    Feb 2004
    Posts
    25
    Any one can answer this question??

  15. #15
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    This:
    Code:
    [...]<SELECT
    <option value="cust_1"<cust_1
    <option value="cust_1"<cust_2
    <option value="cust_3"<cust_3
    </SELECT>[...]
    must be:
    Code:
    [...]<SELECT name="c_name">
    <option value="cust_1">cust_1</option>
    <option value="cust_1">cust_2</option>
    <option value="cust_3">cust_3</option>
    </SELECT>[...]
    board.perl-community.de - The German Perl-Community

Posting Permissions

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