Forum Moderators: coopster

Message Too Old, No Replies

PHP and HTML; Why won't this link work ?

Such a simple problem

         

Snappa

9:17 pm on Feb 10, 2012 (gmt 0)

10+ Year Member



I have this line of HTML with some embedded PHP, but it doesn't work.
<input type="button" id="opener" value="<?php echo $buttonlabel;?>"><a href = "contactdetails.php?action=edit&C_ID=<?php echo($C_ID);?>" a>

It is called from within a form. The php call to the buttonlabel works OK. When I hover over the button, it changes colour, but I don't see the url in the lower left status bar (FF8).
It does nothing when clicked.
I want it to call the same page, with a different "action", which is a PHP variable. $C_ID contains a valid number.
It seems like such a simple problem, but it has got me beat at the moment.
Thanks.

penders

9:41 pm on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This looks like an HTML query, rather than PHP, but anyway...

When I hover over the button, it changes colour, but I don't see the url in the lower left status bar


The 'url' is not on the button, it's on the anchor element that follows. But your anchor looks incorrectly formed.

Snappa

6:38 pm on Feb 11, 2012 (gmt 0)

10+ Year Member



Thanks Penders.
I noticed a missing "/" on the closing anchor tag, which didn't make any difference. I also played around replacing the php with hard code, and it still doesn't work. I'll post again in the HTML forum.
Cheers.

penders

7:44 pm on Feb 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<input type="button" id="opener" value="<?php echo $buttonlabel;?>"><a href = "contactdetails.php?action=edit&C_ID=<?php echo($C_ID);?>"a>


I was assuming at first that this was just a snippet and that there was more, but maybe this is your complete code? You are not only missing a "/", but your anchor is incomplete, it should be something like...

<input type="button" id="opener" value="<?=$buttonlabel?>"> 
<a href="contactdetails.php?action=edit&C_ID=<?=$C_ID?>">ANCHOR TEXT</a>


(I've used the short echo format in place of
<?php echo ... ?>
)

Snappa

9:19 pm on Feb 11, 2012 (gmt 0)

10+ Year Member



<a href = "contactdetails.php?action=edit&C_ID=<?php echo $C_ID;?>"><?php echo $buttonlabel;?></a>


OK. This now works, except that the link now comes from the text. The button still wasn't working, so I thought I'd eliminate it now, for clarity. So the question now is "How to convert the link text into a button. Definitely HTML, but I'd like to see if I can continue here, please.
Thanks for your help.

penders

11:53 pm on Feb 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, as you have found, if you want a link you need to use an anchor element. Alternatively you could add an onclick event to the <input type="button", but then your page is dependent on JavaScript. The accessible way to implement this would be to include the anchor as part of the page and then, using JavaScript, replace this anchor with the INPUT - if you really want a traditional (OS specific) button.

However, you can style the anchor to make it look like a button...

How to convert the link text into a button. Definitely HTML, ...


Actually, this is now CSS. :) Add a class to your anchor and define this class in your stylesheet, something like:

HTML:
<a class="button" href="...


CSS:
a.button { 
border: 2px solid #999;
border-color: #eee #999 #999 #eee;
background-color: #ccc;
color: #000;
padding: 0 0.5em;
}
a.button:hover {
border: 2px solid #f66;
border-color: #fee #f66 #f66 #fee;
background-color: #fcc;
}

rocknbil

5:57 pm on Feb 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^ ^ That's really what you want anyway. :-)

The answer to "why didn't the link work as a button?" The input type=button has no inherent behavior and it must be assigned via Javascript (as above.) Even if it did, buttons are for forms. If you must use a form, use a submit button. This will work the same as a link but is really the long way around the fence for a "link button."

<form method="get" action="https://example.com">
<input type="submit" value="Go to URL">
</form>

That will "get" the URL example.com - emulating the behavior of a link.