# Using image\_tag as submit button inside form\_for block

**URL:** <https://www.ruby-forum.com/t/using-image-tag-as-submit-button-inside-form-for-block/184980>\
**Category:** Rails\
**Created:** [March 11, 2010, 11:52am UTC](https://www.ruby-forum.com/t/using-image-tag-as-submit-button-inside-form-for-block/184980 "2010-03-11T11:52:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liberty1776](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Liberty1776](https://www.ruby-forum.com/u/Liberty1776)\
**Post date:** [March 11, 2010, 11:52am UTC](https://www.ruby-forum.com/t/using-image-tag-as-submit-button-inside-form-for-block/184980/1 "2010-03-11T11:52:39Z")

</div>

Hi,

## I’m using standard Rails form builder form\_for and haml. I’m trying to replace standard Rails submit button with an image. In addition Javascript runs on submit event. How can I replace the f.submit button by an image-based button?

remote\_form\_for(@message, :html =\> {:onsubmit =\> “jQuery(`)”})
do |f|
= f.error_messages
%table`

- #… regular form fields with some more indentation …  
= f.submit ‘Send It’

firing. Plus it’s a security bomb if JS is disabled in browser.  
= link\_to image\_tag(‘message\_send.png’), :action =\>  
‘create’, :method =\> :post, :id =\> @message

* * *

Would really appreciate your help.

Thank you,  
Michael

---

<div class="post-metadata">

**Author:** ![Liberty1776](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Liberty1776](https://www.ruby-forum.com/u/Liberty1776)\
**Post date:** [March 11, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/using-image-tag-as-submit-button-inside-form-for-block/184980/2 "2010-03-11T12:35:24Z")

</div>

I don’t know much about haml, but I wanted the same thing than you.  
Here’s what I did

\<% form\_remote\_tag( :url=\>{:action=\>‘moderate’,  
:controller=\>‘messages’},  
:html=\>{:id=\>‘new\_message\_form’},  
:complete=\>“Form.reset(‘new\_message\_form’)”) do %\>  
\<%= hidden\_field\_tag ‘whatever’ %\>

Text  
 \<%= text\_area 'message', 'text', :rows=\>3 %\>

...... 

\<%= image\_submit\_tag "button.png", :name =\> "submit", :onClick =\> "some JS here" %\>

\<% end %\>

Hope this helps,

Christophe

Le 11 mars 2010 à 06:27, Liberty1776 a écrit :
