Form Get方法:防止在查询字符串中提交空字段 [英] Form Get Method: prevent empty fields from submittion in query string
问题描述
搜索表单包含2个部分,
首先通过一些选择,输入和提交按钮进行简单搜索。
第二个包含许多选择,复选框,收音机,输入和提交按钮。
我使用GET方法,因为我想要查询字符串中的所有字段。
example.com/cars-parts/cars-for-sale/?country=205&city=19&cars_category=462
但问题是如果用户不要选择一些字段(因为他不想应用这个标准)很多空字段并且查询字符串太长。
问题:
我想在表单提交之前删除(禁用或任何需要的)所有空字段,以便查询字符串只包含具有值的字段。
注意:只建议使用Form Get Method。在过去,我使用的是POST方法,并且查询字符串中没有传递任何值,但现在我需要查询字符串中的值。
感谢您阅读。
$在你的 $(function(){...})
中使用下面的代码:$ b $ div class =h2_lin>解决方案部分: $('form')。submit(function(){$('input [value =]',this ).remove(); return true;})
这将删除任何空的提交之前,从表单中输入
元素。你当然可以修改它,以包括未选择的选择框等。
I am developing a search form.
Search Form has 2 parts, First simple search with some select, input, and submit button. Second contains many select, check box, radio, input and submit button.
I am using GET method as i want all fields in query string like. example.com/cars-parts/cars-for-sale/?country=205&city=19&cars_category=462
But the issue is if user don't select some fields(because he donot want to apply this criteria) a lot of empty fields and make query string too long.
Problem:
I want to remove (disable or whatever needed) all empty fields before form submission, so that query string includes only fields having value.
NOTE: Only suggest using Form Get Method. In Past i was using POST method and no values were passed in query string, but now i want values in query string.
Thank you for reading.
Try using the following in your $(function(){ ... })
section:
$('form').submit(function(){$('input[value=]',this).remove();return true;})
this will remove any empty input
elements from your form before submitting it. You can of course modify it to include also non-selected selector boxes etc.
这篇关于Form Get方法:防止在查询字符串中提交空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!