image_submit_tag
image_submit_tag(source, options = {})
public
Displays an image which when clicked will submit the form.
source is passed to AssetTagHelper#image_path
Options
- :confirm => 'question?' - This will add a JavaScript confirm prompt with the question specified. If the user accepts, the form is processed normally, otherwise no action is taken.
- :disabled - If set to true, the user will not be able to use this input.
- Any other key creates standard HTML options for the tag.
Examples
image_submit_tag("login.png") # => <input src="/images/login.png" type="image" /> image_submit_tag("purchase.png", :disabled => true) # => <input disabled="disabled" src="/images/purchase.png" type="image" /> image_submit_tag("search.png", :class => 'search-button') # => <input class="search-button" src="/images/search.png" type="image" /> image_submit_tag("agree.png", :disabled => true, :class => "agree-disagree-button") # => <input class="agree-disagree-button" disabled="disabled" src="/images/agree.png" type="image" />
A work-around for adding confirmation to image_submit_tag
Sometimes you may want to add a confirmation to image submit tags but this function does not allow it. To get over this limitation use a normal submit tag and set the src and type properties (set type to “image”)
Code example
submit_tag “Delete”, :confirm => “Are you sure?”, :src => “/images/trash.png”, :type => “image” %>
Adding "alt" text to the image tag
<%= image_submit_tag (“create.gif”, :alt => “Create new entity”) %>
This way when the images are disabled or don’t work you get the nice custom text instead of the standard one. Pretty useful.