简体   繁体   中英

Do not include hidden field in query string when submitting form with GET

http://localhost:3000/users?utf8=%E2%9C%93&search=aen

Here's my form in the view:

<% form_tag users_path, :method => 'get', :html => { :class => 'ui-form' } do %>
    <div class="ui-input ui-input-search">
      <%= text_field_tag :search %>
    </div>
  <% end %>

Which generates a hidden field that gets submitted:

<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div>

Set the disabled attribute on the field you don't want to submit.

Or is the real question about how to get rails to not create that hidden field in the first place?

如果您使用form.serialize()删除不必要的参数部分并使用新的参数创建新的get请求,则可以使用JS完成此操作

You can try doing something like this in an onsubmit function:

document.getElementsByName('utf8')[0].disabled = "disabled";

to prevent it from being sent.

Here's a jquery snippet - add it to your layout to disable the utf8 field in all GET forms

:javascript
      $('form[method=get] input[name=utf8]').attr("disabled", "disabled");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM