Closed (fixed)
Project:
Webform
Version:
6.x-3.2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Jan 2009 at 23:31 UTC
Updated:
30 Sep 2012 at 19:42 UTC
I made a tiny module that alters a webform's submit button, turning it into an image_button (code example below). But, now the form doesn't submit and redirect to the confirmation message, instead the form reloads as if it didn't post.
Code example:
// other code then...
unset($form['submit']['#value']);
$form['submit']['#type'] = 'image_button';
$form['submit']['#src'] = drupal_get_path('theme', 'mytheme') .'/images/webforms/button-submit.gif';
//$form['submit']['#button_type'] = 'submit'; // tried this too
//$form['submit']['#submit'] = TRUE; // tried this too
//... then more code.
Comments
Comment #1
quicksketchSee #361103: Pager buttons not checked right and #241523: Allow back and next buttons to customised
Comment #2
FrancS commentedProblem could be in way which browser send value of submit image button.
For example if value of submit button is "send" then for image submit button could be "send_x" and "send_y". Browser added x and y coordinate postfix.
If module control if submit was posted by checking it value then this test fail.
I hope this help.
Comment #3
quicksketchThe 3.x version now allows form_altering of these buttons because it is no longer dependent on the label of the button, per #361103: Pager buttons not checked right.
Comment #4
leo pitt commentedI am also having the same problem, but the site is live so I do not want to install a dev version of the module.
I have worked around the issue by using CSS backgrounds instead of image buttons for the time being.
Any idea when we can expect a production release of 3.x?
Comment #5
kruser commentedI tried to form_alter override with version 3 beta, and it still isn't submitting the form, just refreshing. Is there something else I should be changing?
Comment #6
m4oliveiHi,
I'm having this same issue in the 6.x-3.2 version. Here is my code inside of a custom module I am using:
When I do this form alteration, the form is altered as I would expect, but when the form is submitted, nothing actually happens, no email, no entry in Results tab. My understanding from #3 is that this simple form alteration should work. Is there anything I'm missing?
Thanks,
Matt
Comment #7
quicksketchI would suggest using CSS replacement on your buttons rather than using an #type = 'image'. I think the problem is more inline with what #4 suggests, which is that browsers do not submit the same values for image buttons as they do for normal ones. IE is particularly bad about submitting completely random text as the value instead of anything useful. It may be possible that forms with multiple buttons do not work with image buttons in Drupal, I'm not entirely sure.
http://www.ampsoft.net/webdesign-l/image-button.html
Comment #8
m4oliveiAfter playing with it a bit more, I ended up doing exactly what you suggest. I think your right in terms of form submission with image buttons vs submit buttons. Thanks for the link that was really useful, my CSS was exactly the same save for the text-indent style which is very useful. I was just setting the Submit button text to a space, but using text-indent is much better.
Btw, I'm kinda new at adjusting the status (although I did read teh handbook page), so please change to something more appropriate if need be.
Thanks,
Matt
Comment #9
visuallemon commentedhey, would you have any ideas how to style? webform's file upload field button?
I just want to show image instead of default button.
Any ideas on this one?
Comment #10
ndz commentedyou should change name of the button,
default name for image_button is "submit" - webform requires "op" name
the solution is:
$form['submit']['#type'] = 'image_button';
$form['submit']['#attributes'] = array('src' => '/path_to_button/button_name.jpg');
$form['submit']['#name'] = 'op';
have a nice day
Comment #11
El Bandito commentedHi
I'm trying to achieve the CSS override using CSS and webform 6.x-3.11. Sadly I'm confused ( again, doh ! ) as the page Quicksketch links to ( http://www.ampsoft.net/webdesign-l/image-button.html ) is targetting an html button, but the code Firebug is showing me for the submit button within my webform is :
There is no button element.
Any pointers appreciated.
Many thanks,
El B
Comment #12
El Bandito commentedThe answer to my own question ( thanks m4olivei ) is to style the input element as the link suggests for a button. Simples.
El B
Comment #13
gbell12 commentedNot sure if the above is correct for D6, but it's definitely not right for D7.
Same idea, but different structure. You want something like this:
$form['actions']['submit']['#value'] = t(' ');
$form['actions']['submit']['#type'] = 'image_button';
$form['actions']['submit']['#name'] = 'op';
$form['actions']['submit']['#src'] = drupal_get_path('theme', 'theme_name'). 'images/submit_button.png';
As the original states, the "#name = op" part seems to be the critical missing bit when changing the type from "submit" to "image_button".
Thanks ndz, you saved me! Would like to know how you figured this out.
Comment #14
utneon commentedI used this override function in my template file for webform drupal 7:
solved the problem
Comment #15
cooldeeponline commentedhey thank you so much.. i tried quite a number of ways already.. talked with some guys out there in drupal chat too but nothing helped.. and i just tried your tip and it worked.. I was trying to use hook_form_alter along with 'webform ajax' module and the form wasn't submitting. It worked only when I disabled the 'webform ajax' module, but i wanted to use Ajax..
here's my working code: