• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

Passing an argument through a A HREF tag.

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
cide
Asked:
cide
  • 4
  • 3
  • 3
  • +2
1 Solution
 
ozoCommented:
<A href = "Smessage.pl?Username">
Would pass Username in $ENV{QUERY_STRING}
0
 
cideAuthor Commented:
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
 
icdCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
cideAuthor Commented:
Ok, thanks anyways.
0
 
Michel PlungjanIT ExpertCommented:
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
 
cideAuthor Commented:
That's not an argument.  It's still form data.
0
 
Michel PlungjanIT ExpertCommented:
But it is not via QUERY_STRING

Last attempts:
Use a stub and call your program that needs the argv as a subroutine
0
 
jakedCommented:
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
 
ozoCommented:
Actually, in Perl that would be $ARGV[0]
0
 
jakedCommented:
You are right sir.
0
 
ozoCommented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
ozoCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now