18

I'm just trying to create a simple select menu that takes you to a specific URL. So far I have something like this:

# haml
= form_tag new_something_path, method: :get do
  = select_tag :type, options_for_select(my_array)
  = submit_tag 'New Something'

However, when I submit the form I get the UTF8 parameter as well as a "commit" parameter with the text of the button.

How can I remove the UTF8 and commit parameters?

Andrew
  • 227,796
  • 193
  • 515
  • 708
  • This has been answered here: http://stackoverflow.com/a/4488837/523568 Short answer: You shouldn't remove the UTF-8 parameter. Also, you can't get rid of the commit parameter, given that part of the encapsulating form tag. You can change submit_tag's name with `submit_tag name: "whatever", "New Something"` – Tim Dorr Mar 28 '13 at 19:34
  • Yeah, I understand the purpose of the UTF-8 param, but in this case I don't need it because I know the form values will never include any special characters. So I would still like to know how to remove it. – Andrew Mar 28 '13 at 20:02
  • Does this answer your question? [Removing "utf8=✓" from Rails 3 form submissions](https://stackoverflow.com/questions/4487796/removing-utf8-from-rails-3-form-submissions) – Duke Mar 11 '20 at 03:27

2 Answers2

45

Removing the commit param is relatively simple, you need to specify that the input does not have a name:

submit_tag 'New Something', name: nil

Regarding the UTF-8 param...it serves an important purpose. Once you understand the purpose of the Rails UTF-8 param, and for some reason you still need to remove it, the solution is easier than you think...just don't use the form_tag helper:

# haml
%form{action: new_something_path, method: 'get'}
  = select_tag :type, options_for_select(my_array)
  = submit_tag 'New Something', name: nil
Community
  • 1
  • 1
Andrew
  • 227,796
  • 193
  • 515
  • 708
2

You can get rid of the utf8 param by adding the enforce_utf8: false option of form_tag (and also form_form) like the following:

= form_tag new_something_path, method: :get, enforce_utf8: false do

(thanks to @Dmitry for pointing that out)

But please make sure you don't need it: What is the _snowman param in Ruby on Rails 3 forms for? (I'm not sure if it is actually relevant for GET forms.)

The additional parameter is generated by the submit button can be removed by setting the name: false option on your submit_tag (Also works for submit in case of form_for).

= submit_tag 'New Something', name: nil
aef
  • 4,498
  • 7
  • 26
  • 44