Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails submit button text (formtastic) - how to change label of submit button?

I am using simple_form and the following code to create the button.

<%= form.action :submit, :value => "submit", :button_html => { :class => "lagoon" }  %>

However the button is (still) labeled 'Create User' instead of 'submit'. I thought setting the value => would do it but it didn't

like image 397
Michael Durrant Avatar asked Aug 08 '12 14:08

Michael Durrant


People also ask

How to change the text of form submit button in HTML?

Input value attribute The value attribute can be used to change the text of the form submit button. Use value attribute within <input> of type="submit" to rename the button. Example: Change the text of form submit button

What is the use of submit button?

The Submit Button allows a user to trigger submission of the form. The submit button is automatically included on any new form. Submit button settings are available under the Field Settings tab when the submit button element is in focus within the form editor. Submit button as displayed in the Form Editor.

How do I customize the submit button on a gravity form?

By default, the submit button on any form created using Gravity Forms simply reads ‘Submit’. However, we recommend that, for the majority of situations, you customize this text, adding a clear CTA that is relevant to your form and appeals to your audience.

Should I hide the submit button on my form?

Note that hiding the submit button can cause usability issues, which can negatively affect the accessibility of your form. Prior to Gravity Forms version 2.6, the submit button settings were located within Form Settings.


1 Answers

Probably better and correct way is to use :label key and keep :button_html for styling

<%= form.action :submit, :label => "Submit", :button_html => { :class => "lagoon" } %>

I think best idea is to use I18n keys. Check Formtastic docs:

Formtastic decides which label to use in the following order:

  1. :label # :label => "Choose Title"
  2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
  3. Activerecord i18n # if localization file found for the given attribute
  4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method

https://github.com/justinfrench/formtastic

like image 193
remo Avatar answered Sep 20 '22 08:09

remo