Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Does anybody know how to use the new 'image_button'? I'm having trouble to get them to work. For debugging I created a simple form containing two button, a 'normal' button and an 'image_button' (see below). I dont know why, but only the 'normal' button submits the form. The image button only reload the form, but never executes the #submit handler. Any ideas?
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
'#submit' => array('my_submit')
);
$form['buttons']['submit2'] = array(
'#type' => 'image_button',
'#title' => t('Test'),
'#image' => 'path to image',
'#submit' => array('my_submit')
);
Comment | File | Size | Author |
---|---|---|---|
#12 | image_button_0.patch | 4.19 KB | eaton |
#6 | image_button.patch | 3.35 KB | eaton |
#1 | imgbtn.zip_.txt | 1.49 KB | profix898 |
Comments
Comment #1
profix898 CreditAttribution: profix898 commentedI have written a small module to test the behaviour of buttons vs. image buttons. And actually the image buttons do not invoke any handler associated to them (#validate/#submit). I consider this a bug because I dont see why they shouldnt. To verify you can install the attached module (rename to .zip and unpack). I have tested with FF2, IE7, Opera9 on Windows with PHP5. It doesnt seem to be a browser-specific issue.
I found these lines in system.module and both form elements are specified with
'#button_type' => 'submit'
by default. What means they should both submit the form and invoke the handlers. Not?Comment #2
profix898 CreditAttribution: profix898 commentedBecause there is almost no documentation on image buttons I cant even tell if I use them correctly! Anybody?
Comment #3
dvessel CreditAttribution: dvessel commentedLook for the form api at http://api.drupal.org
Image button is not a supported type. You can still alter it from your theme. The handbook pages has information on this.
Comment #4
profix898 CreditAttribution: profix898 commentedIt IS! Image buttons were added recently in http://drupal.org/node/162708 (mainly because they are needed for Views module D6 port). The code I posted above adds an image button as expected, but it does not execute the handlers for some reason. However I'm using them for a JS-powered UI where they work nicely.
Comment #5
dvessel CreditAttribution: dvessel commentedOh snap! That's great! Sorry about that. heh.
I'll take a look a bit later.
Comment #6
eaton CreditAttribution: eaton commentedThe previously committed patch did indeed make it POSSIBLE to implement image buttons correctly, but the actual implementation ofthe image button type appears to have been twitchy. In particular, it was unreliable when at that top level of a form (as opposed to inside of an element with#tree = TRUE.
The attached patch makes things more reliable and adds a dedicated function for processing the incoming values from image buttons, just as checkboxes and other tricky elements have.
There's one other slightly tweaky change: image buttons now use #src for their image path rather than #image. Our FAPI properties generally map to html equivalents, so the previous method was broken.
Anyone willing to test under IE would be a hero -- I've worked with it on FF and Safari now in a variety of configurations.
Comment #7
AjK CreditAttribution: AjK commentedSorry Eaton.
Used test module in #1.
Before patch, observed problem.
After patch.
FF, the image doesn't display but is replaced with the text "test". Clicking it does work (_submit called).
IE, image doesn't display (looks like a 404 on GET image). Clicking however doesn't call _submit :(
Eaton, please ping me in #drupal if you do another patch and I'll IE test for you straight away. That may make your life a little easier. (btw, I only have IE6 at this time. I'm getting a new laptop soon and wil be able to test IE7 but not till that arraives)
Comment #8
AjK CreditAttribution: AjK commented@Eaton, this may help. In order to try and get you some extra info I added this to the top of index.php :-
After patch applied, I got this:-
For FF, _submit is called for bothbutton and image but array() (empty $_POST array)
For IE, hit the submit button _submit called and again array() (empty $_POST array)
But for image button on IE _submit not called and $_POST is this:-
Comment #9
profix898 CreditAttribution: profix898 commented@AjK: Eaton wrote "image buttons now use #src for their image path rather than #image." What means you must change this property in the test module ;)
Images are not broken with the above patch and I can confirm FF to work correctly, but IE is still broken.
Comment #10
eaton CreditAttribution: eaton commentedFound the issue -- Earl Miles' original image button patch had a chunk of helper code that helped it find incoming values in the IE case. That code was dropped from the latest version and the IE issue wasn't spotted. I'm working on the fix right now -- the encouraging news is that the changes from the previous patch DO in fact make it much easier to isolate this fix. Hooray!
Comment #11
profix898 CreditAttribution: profix898 commented@Eaton: Any news? Please let me know if I can do anything to help you with this.
Comment #12
eaton CreditAttribution: eaton commentedOK, here's a patch that uses some of Earl's code from the oooooold version but cleanly encapsulates it so that it only needs to run on image_button types. Anyone with IE? please give this a whirl. ;-)
Also, yes. '#image' is '#src' now -- that was ... arguably an error in the previous patch. Since we hadn't yet documented the EXISTENCE of this element, I think we can safely tweak that. ;)
Comment #13
profix898 CreditAttribution: profix898 commentedGreat job, Eaton (and Earl)! Tested with FF2, IE6/7 and Opera9 and it really works :) Coding style and docs look good as well. I think this is RTBC. The change from '#image' to '#src' shouldnt be much of a problem IMO.
(Maybe we should keep the issue open (after the patch went in) until the existence of image buttons IS documented properly.)
Comment #14
Gábor HojtsyCommitted, thanks!
Leaving this code needs work, until this gets documented (in the update docs and in the FAPI docs).
Comment #15
chx CreditAttribution: chx commentedComment #16
Gábor HojtsyGuys, please help with documenting this, so we can clean this out of the core release blocker issue queue.
Comment #17
eaton CreditAttribution: eaton commentedImage buttons are now documented in the upgrade guide. The FormAPI reference document has fallen terribly out of date (many 5.0 era properties and functions aren't in it) and I'm collaborating with a couple of other developers on a more comprehensive rewrite that would include image_button documentation. Leaving this as 'needs work' for the time being...
Comment #18
eaton CreditAttribution: eaton commentedI've changed this to reflect what actually needs to be done. Now that the upgrade guide lists the information, the real problem is the FAPI reference/Intro.
Comment #19
webchickThis is critical. D6 cannot ship without this essential developer documentation.
Comment #20
moshe weitzman CreditAttribution: moshe weitzman commentedI don't really agree with the critical .We certainly could ship.
We have been more successful with in-code documentation like doxygen comments and the new schema docs. We could attempt a redo along those lines. I really don't know how to do the tables like we currently have.
Comment #21
chx CreditAttribution: chx commentedThen let's demote this. If noone else, then I will work on this but a demote helps.
Comment #22
dpearcefl CreditAttribution: dpearcefl commentedIs this still a problem in current D6?
Comment #23
dpearcefl CreditAttribution: dpearcefl commented