how to pass a parameter in the Hyperlink

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lawrence_chtan
Forum Newbie
Posts: 22
Joined: Mon Jan 02, 2006 8:20 pm
Location: SINGAPORE

how to pass a parameter in the Hyperlink

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

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

Code: Select all

<?php
$value = $_GET['variablename'];
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_GET is populated with information from the URL (query values only)
lawrence_chtan
Forum Newbie
Posts: 22
Joined: Mon Jan 02, 2006 8:20 pm
Location: SINGAPORE

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Actually, if you are posting a form, the value would be in the $_POST['variablename'] array
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply