Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Submit Visitor Info to text or hex file

    I have a home computer, not a server.

    I read an example in a book. When the submit button is pressed, the submitted info was supposed to be displayed as HTML in a web page.

    Instead, the perl program was displayed.

    I would prefer the info go to a text or hex file.

    Code:
    <FORM ACTION="Himages/geturl.pl" METHOD= "GET">
    <B><p>Last Name:<INPUT TYPE= "text" NAME = "LastName" SIZE = "18">
    First Name:<INPUT TYPE= "text" NAME = "FirsttName" SIZE = "18">
    <BR><BR>City:<INPUT TYPE= "text" NAME = "City" SIZE = "21">
    State/Country:<INPUT TYPE= "text" NAME = "State" SIZE = "19">
    <BR><BR><TEXTAREA NAME="Comments" COLS=48 ROWS=5>
    Enter comments.</TEXTAREA><BR><BR>
    <INPUT TYPE = "submit" VALUE = "Send Information"> &nbsp;&nbsp;&nbsp;
    <INPUT TYPE = "reset" VALUE = "Clear Form Fields"></b></form>
    and the perl:

    Code:
    #!/perl/bin/perl
    # geturl.pl
    # get HTML header,ender,define the page title
    require "/pub/scripts/perl-cgi/html.pl"; # Full path
    $Title = "Get Information From A URL";
    # get the query string
    $QueryString = $ENV{'QUERY_STRING'};
    # split into array
    @NameValuePairs = split (/&/, $QueryString);
    # Header,page title,rule
    &HTML_Header ($Title);
    print "<BODY>\n";
    print "<H1>$Title</H1>\n";
    print "<HR>\n";
    # split each pair, print
    foreach $NameValue (@NameValuePairs)
    {
    ($Name,$Value) = split (/=/, $NameValue);
    print "Name = $Name,Value = $Value<br>\n";
    }
    # end document
    &HTML_Ender;
    #  End geturl.pl

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Any computer can be setup as a server, including your home computer.

    Do you have a web server, such as IIS or apache, installed on your computer?

    If not, then installing one would be the first step.

    Once the web server is installed and configured correctly, the script will need to be placed in the directory configured in the web server for the cgi scripts.

    Your script is missing a few very important lines.

    Those first 2 use statement lines should be in EVERY Perl script you write and when writing cgi scripts, you should be using the CGI module instead of manually parsing the query string. The pragmas and module loaded with those use statements will make writing and debugging your script a lot easier.
    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);  # remove this after debugging the script
    
    my $cgi     = CGI->new;
    my %params  = $cgi->Vars;
    my $title   = "Get Information From A URL";
    
    print $cgi->header,
          $cgi->start_html($title),
          $cgi->h1($title),
          $cgi->hr;
    
    foreach my $name ( keys %params ) {
        print $cgi->p("Name = $name, Value = $params{$name}\n");
    }
    
    print $cgi->end_html;

  • Users who have thanked FishMonger for this post:

    vl123456 (02-20-2012)

  • #3
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    To write the data to a file, you first need to open a filehandle and then print the data to that filehandle instead of the default STDOUT filehandle.

    See: perldoc -f open

  • #4
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If i were at home, could i access info stored at a distant server, having the web page it generates display in a frame? this is what i have so far...

    Code:
    <FORM action= "himages\submitanswer.pl" method=post>
        <INPUT value="Get Information" type=submit>
          </FORM></TD  <tr><td>
          <iframe name= "infohere" width = "100%" height = "400">
          </iframe>

  • #5
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    77
    Thanks
    0
    Thanked 12 Times in 11 Posts
    I have a PHP script that saves data into a text file in your interrested.

  • #6
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes please get me the code.

    I thought a <target= "infohere"> would open the cgi html created by the server in my <iframe> at home.

    when i submit in first window, the <iframe> in second window gets the 502, "I.E. cannot display page". when i do the "get info" button in the second window, it displays the perl code in the <iframe>.
    On a server, that is supposed to show a web page? If i have the second window at my home computer, will i get the info? I can't test it myself...

    will i need a <link> command?
    Last edited by Malform11; 02-16-2012 at 02:55 AM. Reason: spelling

  • #7
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I installed D:\strawberry\perl
    When i put perl code in the perl\bin\ or in perl\cgi and try to call it as in previous code nothing happens.
    i put in a relative folder to my HTML and refer to it and the iframe displays perl code.

    How do i make the strawberry run perl?

  • #8
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Are you running the apache web server or IIS?

    The script needs to be put in the directory that is configured in the web server for cgi scripts.

  • #9
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It was the web server version of strawberry for windows. I would like to figure it out, maybe take a perl course.

    I gave up on making my computer a server. I have a website now, my next thing is to put your perl into the right folder, i think, to retrieve data.

    the submit form has

    <FORM action= "perl.bat" method="get" >
    Does that record the input data? Does it need to be in some folder?

    The sign-up said something about not wanting people using the iframe to access private info. i am not trying to do that.

  • #10
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Halfway there

    It appears that the perl works now, a web page prints with the heading. It appears that there is no info being stored for it to access.

    Is there perl to make the submit form do that? The "perl.bat" does nothing.

  • #11
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello hello hello
    Is there anybody in there?
    Just nod if you can hear me
    is there anyone at home?

  • #12
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hello?

    So coding forum is my new girlfriend now, ignoring me and hoping i'll just go away?

  • #13
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    It's common for us volunteers to take weekends off, especially when there is a holiday involved.

    It's hard to tell you what's wrong without seeing your code, and knowing which web server you're using and how you configured it and want errors you're receiving. Strawberry Perl, as far as I know, doesn't come with a web server, so we still don't know what you're working with.

    I would not expect a cgi script called perl.bat to work. The normal extension used for perl scripts is .pl and sometimes .cgi is used. In either case, the web server needs to be configured to understand that it needs to execute the script.

  • #14
    New Coder
    Join Date
    Jan 2011
    Location
    Dallas
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thank you

    The perl worked when i put it in the cgi-bin folder at the website i bought. It displayed the heading, the horizontal line, but no info.

    This was from a book but i added the text area and fitted it to page.
    I just want it to record the info so the perl routine can pick it up.

    <FORM action= "perl.bat" method="get" >
    <B> <P>
    Last Name:<INPUT id="txtLastName" size="18" name="LastName">
    First Name:<INPUT size="18" name="FirstName"> <BR><BR>
    City:<INPUT id="txtCity" size="21" name="City">
    State/Country:<INPUT size="19" name="State"> <BR><BR>
    <TEXTAREA rows="5" cols="48" name="Comments" maxLength="500">Enter comments.</TEXTAREA>
    <BR><BR><INPUT value="Send Information" type="submit">&nbsp;&nbsp;&nbsp;
    <INPUT id="inbutton" value="Clear Form Fields" type="reset">
    </B></FORM>
    Last edited by Malform11; 02-19-2012 at 04:50 PM. Reason: saw error

  • #15
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Please post your complete Perl script.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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