php variable Link Button?

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
liveman
Forum Newbie
Posts: 3
Joined: Tue Jan 18, 2011 4:15 pm

php variable Link Button?

Post by liveman »

Hi, I am trying to implement the following code, however it's just not working, as you can see it's a button which goes to a URL after being clicked, the URL should be that of the variable $test. Any help kindly appreciated :)

<?php
$test = 'http://www.facebook.com/';
Print'
<FORM METHOD="LINK" EVENT="$test">
<INPUT TYPE="submit" VALUE="view Event">
</FORM>'
?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php variable Link Button?

Post by social_experiment »

Code: Select all

<?php
$test = 'http://www.facebook.com/';
Print'
<FORM METHOD="LINK" EVENT="'. $test. '">
<INPUT TYPE="submit" VALUE="view Event">
</FORM>';
?>
Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: php variable Link Button?

Post by anantha »

you can add an onclick event....there are number of ways to do this..

Code: Select all

echo '<INPUT TYPE="submit" onclick="window.location='.$test.'" VALUE="view Event">';
liveman
Forum Newbie
Posts: 3
Joined: Tue Jan 18, 2011 4:15 pm

Re: php variable Link Button?

Post by liveman »

Hi Social_Experiment & Anantha I have tried both of your solutions and nothing is working. Is what I am trying to do actually possible without using Javascript?

It works find on a html link with the following code:

Code: Select all

Print"
<a href='$test'>view Event</a><br/>";
Thanks for your help so far and FYI I have used both Chrome and Safari to check the results :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php variable Link Button?

Post by social_experiment »

Code: Select all

<?php
$test = 'http://www.facebook.com/';
Print'
<FORM METHOD="LINK" EVENT="$test">
<INPUT TYPE="submit" VALUE="view Event">
</FORM>'
?>
The problem might be your form code. There is no EVENT attribute that can be used with the form tag. Also, LINK is not a valid value for method, it's either post, get (of which get is deprecated). If you aren't posting information simply use an anchor tag <a>.

Code: Select all

<?php 
 echo '<a href="'. $test .'">view Event</a>';
 ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply