Page 1 of 1

how to pass a parameter in the Hyperlink

Posted: Sun Feb 12, 2006 8:09 pm
by lawrence_chtan
hi

I am pretty newbie in Web Development :D . I had noticed PHP is passing the information via the OnSubmit function.

Therefore what if i would like to pass the parameter via clicking Hyperlink. how do i get the information at the other screen beside using form post method?

change password

$value1 = $_Hyperlink['StrPassword'];

I m just guessing. :P

Sorry to trouble your valuable time to advice me.

Posted: Sun Feb 12, 2006 8:12 pm
by Benjamin

Code: Select all

http://arg.com/pagename.php?variablename=value

Code: Select all

<?php
$value = $_GET['variablename'];
?>

Posted: Sun Feb 12, 2006 8:12 pm
by feyd
$_GET is populated with information from the URL (query values only)

Posted: Sun Feb 12, 2006 8:33 pm
by lawrence_chtan
Example

test1.php
<html>
<body>
<form>
Email = <a href = "test2.php"> Change password <a> <input type=hidden name="StrEmail" value="abc@abc.com">

</form>
</body>
</html>

test2.php
<html>
<body>
<?php
$value=$_Get['StrEmail'];
echo "value is -> " .$value;
?>
</body>
</html>

Isnt that code is use for form? not for hyperlink?

Posted: Sun Feb 12, 2006 8:38 pm
by Benjamin
Actually, if you are posting a form, the value would be in the $_POST['variablename'] array

Posted: Sun Feb 12, 2006 8:44 pm
by feyd
Although your hyperlink is in the form it does not submit the form, therefore the information is not sent. To submit the form via hyperlink, you need to use the onclick event or script Javascript into the href itself.

Code: Select all

<a href="javascript:document.forms[0].submit();">

or

<a href="#" onclick="document.forms[0].submit">
However, there is one last thing: you should have an action attribute in the form tag to designate where the submission is sent.

Edit: and it's $_GET not $_Get.