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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

value via post with a hyperlink

Status
Not open for further replies.

michelleqw

Programmer
Jan 4, 2004
120
DE
Dear php users,

Is it possible to send via a hyperlink a value to a php page with the help of a post variable. If yes can someone give source?

Source I tried but no results:

<form action="index.php" method="post">
<p align="center">

<?php
echo $_POST['test'] . "<br>";
echo $_POST['xx'] . "<br>";
?>

<input type="submit" name="test" value="test">
<p align="center"><a href="index.php"><name="xx" value="xx">tryout</a></p>
</form>

 
Hi!

If you want to "fill" a post variable with a querystring variable, you simply do:

Code:
if (isset($variable))
  {
    $_POST['variable'] = $variable;
  }

it could be smart to also use: strip_tags():
Code:
if (isset($variable))
  {
    $_POST['variable'] = [b]strip_tags([/b]$variable[b])[/b];
  }
 
If I understand correctly:
You want to further pass a variable that has been posted to a PHP script.
The easiest, low-tech method, is a hidden field where the value is populated from your POST array:
Code:
echo('<input type="hidden" name="myVar" value="'.$_POST['variable'].'">');
This way you can preserve the value and pass it on to the script you post to.
 
It don't works!

I want to send a post variable to a php file with the help of a hyperlink.

Michelle.
 
You can't POST with a link. A link only supports GET variables attached to it as a query string.
 
It is, however, possible to use a hyperlink to submit a form using client side scripting.
Maybe you could explain why you want to use a hyperlink to transfer 'posted' values - from there we can suggest alternative methods of achieving what you want to achieve.
 
I gave her the sollution above!
I actually gave her two sollutions, one: sessions, the other: pass with variable as querystring, do an if (isset($var)) {$_post['var'] = $var;}

I will make example files for her tomorrow..
header("location: bed");
 
ascikey: yeah, I guess she can use the
Code:
$_POST['var'] = $_REQUEST['varname'];

What will also work, is what I gave sample for above:
Code:
$_POST['var'] = $var;

she does not need to "request" the variable, since it has been made in the querystring.. (eg. from a hyperlink).

example:

whatever.php:
Code:
<?php

if (isset($blah))
  {
    $_POST['blah']  = $blah;
    echo $_POST['blah'];
  }
else
  {
    echo "<a href=\"?blah=foo\" title=\"bar!\">yo!</a>";
  }
?>

you could also put the entire querystring in an variable/array..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top