submit
![Extensive documentation Importance_4](https://d2vfyqvduarcvs.cloudfront.net/images/importance_4.png?1349367920)
submit(value=nil, options={})
public
Add the submit button for the given form. When no value is given, it checks if the object is a new resource or not to create the proper label:
<%= form_for @post do |f| %> <%= f.submit %> <% end %>
In the example above, if @post is a new record, it will use “Create Post” as submit button label, otherwise, it uses “Update Post”.
Those labels can be customized using I18n, under the helpers.submit key and accept the %{model} as translation interpolation:
en: helpers: submit: create: "Create a %{model}" update: "Confirm changes to %{model}"
It also searches for a key specific for the given object:
en: helpers: submit: post: create: "Add %{model}"
![Default_avatar_30](https://www.gravatar.com/avatar/e556f4b23552aa95b4a3b41a2cb61742?default=http://apidock.com/images/default_avatar_30.png&size=30)
![Default_avatar_30](https://www.gravatar.com/avatar/174330d280860a6ad77a6d15dd7fabe1?default=http://apidock.com/images/default_avatar_30.png&size=30)
![Default_avatar_30](https://www.gravatar.com/avatar/da30ad285b0d9217227f6d80ad01dcca?default=http://apidock.com/images/default_avatar_30.png&size=30)
About the options argument
The options are not documented, but of course you can use the same options than submit_tag.
Note that all non-documented options are simply passed to the input tag. Amongst other things, this allows you to change the default name attribute (commit):
form.submit 'Cancel', :name => 'cancel'
That’s very handy in forms with multiple submit buttons, this way the controller can easily check in the params which action was submitted.
![Default_avatar_30](https://www.gravatar.com/avatar/474774ea98d31fa24693366369acb777?default=http://apidock.com/images/default_avatar_30.png&size=30)
submit button with rails javascript's onclick event handler method
Code example
<%= f.submit ‘Create User’, class: ‘buttons’, :onclick => “validate_user_form_and_submit()” %>
![Default_avatar_30](https://www.gravatar.com/avatar/5c7a5fcd85529e17f9aa86c1e9a5490e?default=http://apidock.com/images/default_avatar_30.png&size=30)
Access just the label text
One of the handiest features of `f.submit` is the auto-generated label text.
Some styling frameworks don’t lend themselves to using `f.submit` without lots of tweaking.
If you’re not using `f.submit` but still want to access the label text, note that there is a private method:
f.send(:submit_default_value)
One example (in Haml, using MaterializeCss):
.row .col.s6.center %button{ type: 'submit', name: 'commit', data: { disable: { with: 'Submitting...' } }, class: 'waves-effect waves-light btn maroon' } = f.send(:submit_default_value)