Solved

Passing an argument through a A HREF tag.

Posted on 1998-04-25
13
404 Views
Last Modified: 2013-12-25
Greetings,
      I want to run a Perl script using an A HREF tag, and be able to pass a variable along with it as well.
example:
<A href = "Smessage.pl Username" target ="Frame5">Send</a>
The script would recieve "Username" as an argument (I'm using perl and would like to use $ARGV).  If it's not possible to do this with an argument how would I do this as a get/post action?  I've seen it done on the web before.  Much like a banner advertisement sending the page owners name to the cgi script.
Thanks in Advance.
0
Comment
Question by:cide
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1827966
<A href = "Smessage.pl?Username">
Would pass Username in $ENV{QUERY_STRING}
0
 

Author Comment

by:cide
ID: 1827967
Yeah, I know how to do that.  I was wondering if it was possible through the $ARGV.  I don't really want to use the QUERY_STRING but maybe I'll have to.
0
 
LVL 5

Expert Comment

by:icd
ID: 1827968
You only have two options. The method that ozo gave uses the GET method which puts the data in the QUERY_STRING. With a form (but not with a HREF) you can use the POST method which puts the data in stdin. There is no other way.

0
 

Author Comment

by:cide
ID: 1827969
Ok, thanks anyways.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1827970
Try this:

<FORM NAME="msgform" ACTION="Smessage.pl" METHOD="POST" TARGET="Frame5">
<INPUT NAME="USERNAME" TYPE="HIDDEN" VALUE="">
</FORM>
<A HREF="javascript:document.msgform.USERNAME.value='username1';document.msgform.submit();">User name 1</A>

Michel
0
 

Author Comment

by:cide
ID: 1827971
That's not an argument.  It's still form data.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1827972
But it is not via QUERY_STRING

Last attempts:
Use a stub and call your program that needs the argv as a subroutine
0
 
LVL 2

Accepted Solution

by:
jaked earned 50 total points
ID: 1827973
Actually, the CGI spec says that if the query string is of the form ?foo+bar+baz, rather than ?foo=bar&baz=quux, it gets split on the pluses and passed in as the arglist to the script. So ozo's example passes Username as argv[1] as well as in the QUERY_STRING environment variable.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1827974
Actually, in Perl that would be $ARGV[0]
0
 
LVL 2

Expert Comment

by:jaked
ID: 1827975
You are right sir.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1827976
Even so, I'd hesitate to recommend using $ARGV[0] rather than $ENV{QUERY_STRING}
If you ever did get an = there, you could lose the @ARGV parameters
(You'd have to use something like ?foo%3dbar&baz%3dquux in that case)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1827977
When I needed to have a program running as a cgi AND standalone, I would test the arguments passed and if empty I would look at the environment variables.

Michel
0
 
LVL 84

Expert Comment

by:ozo
ID: 1827978
But as jaked points out, you can't rely on @ARGV being empty when running as a CGI.
Also, you omit the case of parameters being passed in STDIN.
BTW, with
 use CGI.pm;
all the arg parsing is done for you as a CGI, and you can also
pass arguments on the command line or in STDIN for stand alone testin.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell Find Folders 7 52
need a quick help to fix the script logic 4 63
Need help editing script 3 65
Using a variable to name output in powershell script 2 29
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now