1

I have an AJAX form that works as expected with the following submit code:

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Go'),
);

I want to use an image for the button, but the type 'image_button' breaks the AJAX functionality (multiple repopulating select fields, won't appear, or update):

$form['submit'] = array(
  '#type' => 'image_button',
  '#src' => '/themes/moon/images/go.gif',
  '#value' => t('Go'),
);

Oddly, the 'image_button' works fine when clicking it (form works as expected) it's just the AJAX updating of the form that stops working? Drupal Form API Reference

  • Is this a custom form and you bind the '#ajax' property to these submit elements yourself, or is it an existent form that you are trying to customize? – ovi Mar 26 '12 at 20:48
  • It's a custom form, but the submit element doesn't even have an #ajax property. Only the first & second select lists have an #ajax property. If anybody wants, I can post the whole form in the question. – Merrick Mar 26 '12 at 20:58
  • Can you post the code relevant to this issue in the question, so we can understand the problem better. – SN_26 Aug 19 '13 at 7:12
  • Hi @ShabanaBlackborder, over a year later!? I'm not with that company anymore, but if I had to guess they're still working on that project (lol). – Merrick Aug 19 '13 at 17:42
  • Hehhee, oops, sorry there. Didn't even see the date!!! – SN_26 Aug 20 '13 at 5:52
1

You have to set an unique '#name' tag for EVERY button (submit, image_button, button) on the page. This worked for me.

| improve this answer | |
0

Heads up that if you are using ctools modals, there is a bug with image buttons such that they aren't submitted when clicked (you can look at your POST details to check what values are submitted). I created a patch here that seems to fix it: https://www.drupal.org/node/1314894

| improve this answer | |
-2

Remove the #value from image button..

| improve this answer | |
  • 4
    Welcome to Drupal Answers :) Answers here are expected to be of a higher quality than this. Please can you expand on what you mean, and perhaps explain why you feel removing #value from the element array will fix the problem – Clive Dec 6 '12 at 9:01
  • With only 7 points @modhura doesn't seem to be DSE regular. Perhaps someone else could explain and get theirs accepted instead – vfclists Oct 21 '13 at 20:52
  • This worked for me when I had 2 x image_buttons, one for 'Submit' and one for 'Preview'. Nothing else worked cross browser except for unsetting #value. I didn't look into why this happens :( – leexonline Mar 31 '14 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.