Link to home
Start Free TrialLog in
Avatar of sayhi
sayhi

asked on

passing variables

i have this form which has predefined names and values embedded in it, but there are some values that the user can enter... i want to write a script that logs and/or emails those variables and then plug them into another script... kinda like:
http://mydomain.com/cgi-bin/welcome.pl?&name=USERINPUT&name=predefinedvalue&name=USERINPUT&name=value etc

if anyone could give me tips on how i could do this or if i'm making any sense (i've just begun learning basic perl and cgi stuff) or just point me in the right direction, it'd be a great help!
Avatar of ozo
ozo
Flag of United States of America image

If I am understanding you, it sounds like you want to set a
Location:
header, or a <META HTTP-EQUIV="REFRESH"> tag
Or else fetch the URL yourself, which can be be done with perl modules like
use LWP::Simple;
or
use LWP::UserAgent;
Avatar of Motaz
Motaz

If you use FrontPage Express you can
drop a Submit button, and at forms properties click Settings then write your CGI executable file at Action edit box, select method of sending these values (Post or Get) I prefere Post, because it is more secure, by it you can send password, but you cann't if you use Get, because the password will appear at Address area. when the user open this page and enter some data in different fields then he/she click on Submit button all these data will be sent to your CGI or PERL application.

Motaz
Hope this helps you out :

####### In your HTML :

<form method=post action=script.pl>


######## In your CGI :

#!/usr/bin/perl

#
# To handle input from forms / URL
#


#Putting the Query_string into a variable
      if ($ENV{'REQUEST_METHOD'} eq POST)
            {
            $DataLength=$ENV{'CONTENT_LENGTH'};
            read (STDIN, $QueryString, $DataLength);
            }
      else
            {
            $QueryString = $ENV{'QUERY_STRING'};
            }

#Splitting the pairs and putting them in a list
      @NameValuePairs = split (/&/, $QueryString);

#Preparing for HTML stuff
      open (LOG, ">>log.txt");
      print "Content-type: text/html","\n\n";      # MIME header

      print "<HTML>","\n";
      print "<HEAD>","\n";
      print "<TITLE>","Parameters sent in","</TITLE>","\n";
      print "</HEAD>","\n\n";
      print "<BODY>","\n\n";
#Separating the pairs and displaying them on screen.

      $n = 0;
      foreach $NameValue (@NameValuePairs)
      {
            ($Name, $Value) = split (/=/, $NameValue);
            $Value =~ tr/+/ /;
            $Value =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C", hex ($1))/eg;

            print LOG "Variable=$Name, Value=$Value <BR>\n";
            print "Variable=$Name, Value=$Value <BR>\n";
            $MyVarList[$n]=$Name;
            $MyValList[$n]=$Value;
        $n++;
      }

      print "</BODY>","\n\n";
      print "</HTML>","\n\n";

if you want to plug them into another script then yo could write your first script like the one above, but put a form in the returned webpage.

this form should have a hidden field for each value that you want to pass onto the next script, and the submit button should call your new script.

that will pass them onto the new script.
Avatar of sayhi

ASKER

ok, i've got a good start with all your comments, BUT i only want to record what the user inputs, can u record only certain variables?
another thing is this LWP module, i looked it up and think it's for people who have there own server. how do i check if my webhosting provider has this module? or can i install this in my directory?

if i can't use this, what's the way to redirect to another URL within the cgi script?
Avatar of sayhi

ASKER

well, i figured out how to get the variables i want by doing @userinput = @formdata{'input1', 'input2'};

i think i'll do a little more reading and see what i can do ;)
Avatar of sayhi

ASKER

ok this is what i've came up:

#!/usr/bin/perl

require "subparseform.lib";
&Parse_Form;

print "Content-type: text/html\n\n";

@userinput = @formdata{'input1', 'input9'};

$input1 = @formdata{'input1'};
$input9 = @formdata{'input9'};

open (LOG, ">>log.txt");
print LOG "@userinput\n";
close(LOG);

#go to 2nd cgi
print <<"REDIRECT";
      <HTML>
      <HEAD>
      <TITLE>
      </TITLE>
      <META HTTP-EQUIV="refresh" CONTENT="0; URL=https://some.domain.com/cgi-bin/welcome.pl?&field1=$input1&field2=....&field9=$input9&field10=">
      </HEAD>
      </BODY>
      </HTML>

REDIRECT


And it works!

still, i've got one more question... how could i do this with the post type method? i know it might have to do something with STDIN.
ASKER CERTIFIED SOLUTION
Avatar of ianB
ianB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial