[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

passing variables

Posted on 2000-01-20
8
Medium Priority
?
175 Views
Last Modified: 2013-12-25
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!
0
Comment
Question by:sayhi
8 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 2373352
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;
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2373469
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
0
 
LVL 1

Expert Comment

by:Kenny
ID: 2373814
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";

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:BillyAbbott
ID: 2374281
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.
0
 
LVL 1

Author Comment

by:sayhi
ID: 2376283
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?
0
 
LVL 1

Author Comment

by:sayhi
ID: 2376717
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 ;)
0
 
LVL 1

Author Comment

by:sayhi
ID: 2376847
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.
0
 
LVL 5

Accepted Solution

by:
ianB earned 800 total points
ID: 2410921
Hi,

i am splitting the points on this question, per the users request, the points will be broke like this :

ozo > 65
Motaz > 50
zxr250 > 65
BillyAbbott > 20

Each expert will find their questions posted in this area.

Ian
Community Support @ Experts Exchange
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

608 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