Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way with rails form helper to produce a button tag for submit

I am trying to create buttons ala Wufoo (Rediscovering the button element)

I would like to write the following code like the following:

<%form_tag search_path, :method => :get, :class => 'search' do %>   <%=text_field_tag :search, params[:search] -%>   <%=button_tag 'search', :name => nil-%> <%end%> 

To generate the following HTML (instead of the input[type="submit"] tag)

<button type="submit" class="positive">     <img src="/images/icons/tick.png" alt=""/>      Save </button> 

Does a method exist already? Or should I roll my own helper?

like image 320
Jonathan Avatar asked Feb 12 '10 19:02

Jonathan


People also ask

How do I submit a button tag?

Inside a <button> element you can put text (and tags like <i> , <b> , <strong> , <br> , <img> , etc.). That is not possible with a button created with the <input> element! Tip: Always specify the type attribute for a <button> element, to tell browsers what type of button it is.

Which tag is used to create submit button?

The <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a file on the server with a script for processing input data. The form-handler is specified in the form's action attribute.

Do forms need a button to submit?

If you don't have any submit button it is acceptable after all it is an element of form tag and if it is not required you may not add it with in form . This will not broke any web standard.

Does HTML button submit form?

submit : The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form> , or if the attribute is an empty or invalid value.


1 Answers

You could use content_tag to achieve this. It's the more railsy way of doing what you want. But it's longer than the raw HTML.

<% content_tag :button :type => :submit, :class => :positive do %>    <%= image_tag "icons/tick.png"%>    Save <% end %> 

Which produces

<button type="submit" class="positive">     <img src="/images/icons/tick.png" alt="Tick"/>      Save </button> 

However using this as a starting point you should have no problem rolling your own robust helper, or abstracting it to a partial.

like image 99
EmFi Avatar answered Sep 21 '22 18:09

EmFi