Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forms and href problem

Status
Not open for further replies.

maslett

Technical User
Mar 11, 2004
121
0
0
GB
Hi, i have a website that passes data between scripts using both links (ie href=script.pl?data=yay&etc=etc) and forms (using the post method). The problem is I want to pass some private data using a link - I could use a form (method=post) - but I really *want* to use a link. I have tried

Code:
<form method='post'>
<input type='hidden' secret_data='$data'>
<a href='/cgi-bin/display.pl'>Link</a>
</form>

but when I click the link no data is passed. When I display the $ENV variable REQUEST_METHOD it shows GET as the method instead of POST (as I would have expected).

Anyone???????

Ta,
Matt
 
Links and forms are mutually exclusive. To do what you're looking for, you'll want to look into a JavaScript solution to build the URL with the extra data, and/or submit the form itself.

While my JavaScript is very rusty and there is a better way to do this, something like this perhaps:
Code:
<script type="text/javascript" language="Javascript">
<!--
function submitme()
{
var myactionurl = "[URL unfurl="true"]http://www.domain.com/cgi-bin/display.pl?secret_data="[/URL] + element[0] + "&otherdata=" + element[1];

document.forms[0].action = myactionurl;
document.forms[0].method = "post";
document.forms[0].submit();
return true;

}

// -->
</SCRIPT>

<a href="javascript:void(0)" onClick="submitme();">Link name</a>

- Rieekan
 
Cheers Rieekan, I'll have a go over the weekend and post my results!
 

<a href='/cgi-bin/display.pl?secret_data=$data;'>Link</a>

<form method='post' action='/cgi-bin/display.pl'>
<input type='hidden' name='secret_data' value='$data'>
</form>

In either case the variable $data is not populated
with anything just yet.
To populate the variable $data, you can:
1) Type in the secret data when you build the page.
2) Use javascript as mentioned above.
3) You can use perl to populate the variable if you
are building the page dynamically using perl, php or
some other language.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top