drake
drake

Reputation: 61

how to use variable name with image tag

my controller uses code like this:

if  params[:commit] == "Submit"

this used to work fine when I just had buttons. however, now I am using images as buttons like below:

<%= image_submit_tag 'butons/Add-08.png',  :class => 'image-button-submit' %>

How can I pass the commit variable with value Submit along with this image_submit_tag?

Upvotes: 2

Views: 520

Answers (3)

Jon Moses
Jon Moses

Reputation: 138

KandadaBoggu is right, but that will (in most browsers) give you a params['commit.x'] and params['commit.y'] rather than just params['commit'].

If there's only the one button on the form (and you're posting to the same action that renders the form) you can do if request.post? instead, but that's only going to work if there's just one button, ie: only submit, not submit and cancel.

Upvotes: 2

Harish Shetty
Harish Shetty

Reputation: 64363

As per the image_submit_tag documentation you can pass any HTML options. I haven't tested this but the following code should work.

<%= image_submit_tag 'butons/Add-08.png', :name =>"commit", :value =>"Submit" %>

Upvotes: 1

mtwstudios
mtwstudios

Reputation: 76

I would try passing it as a hidden field inside of the form you're submitting.

hidden_field_tag "commit", "Submit"

Upvotes: 0

Related Questions