Created
June 14, 2011 18:01
-
-
Save gavinblair/1025461 to your computer and use it in GitHub Desktop.
Drupal 6 - make external image_buttons work like D7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//you could also add this to your theme's template.php file, by replacing "phptemplate_image_button" with "themename_image_button" in the function name. | |
function phptemplate_image_button($element) { | |
// Make sure not to overwrite classes. | |
if (isset($element['#attributes']['class'])) { | |
$element['#attributes']['class'] = 'form-'. $element['#button_type'] .' '. $element['#attributes']['class']; | |
} | |
else { | |
$element['#attributes']['class'] = 'form-'. $element['#button_type']; | |
} | |
$src_uri = $element['#src']; | |
$data = explode('://', $src_uri, 2); | |
$scheme = count($data) == 2 ? $data[0] : FALSE; | |
if (!$scheme) { | |
$src_uri = base_path() . '/' . $element['#src']; | |
} | |
return '<input type="image" name="'. $element['#name'] .'" '. | |
(!empty($element['#value']) ? ('value="'. check_plain($element['#value']) .'" ') : '') . | |
'id="'. $element['#id'] .'" '. | |
drupal_attributes($element['#attributes']) . | |
' src="' . $src_uri . '" ' . | |
(!empty($element['#title']) ? 'alt="'. check_plain($element['#title']) .'" title="'. check_plain($element['#title']) .'" ' : '' ) . | |
"/>\n"; | |
} |
IIRC inputs typed to image send the coordinates on the image where they clicked, so technically they're sending more data (although not much).
button elements can be assigned as submit buttons natively whereas image types would need JS in order to dispatch submit form on click/enter.
Both are valid. (S/T/F)
Button elements are more useful in most cases.
Thanks e1nherjar. I tried disabling javascript in Firefox and click+enter still worked on the image button.
You're right about the coordinates of the click event, in my case it's no biggie.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my case it's a "Pay with PayPal" button. Image buttons make sense, they are valid HTML, no?