Is it possible to pass some form fields in a GET request?

I have a form with some input passed to GET, and I don't want to have all fields in GET; I want to avoid empty fields.

So, a concrete example for:

<form method="GET" action="an_url">
    <input type="text" name="field1"/>
    <input type="text" name="field2"/>
    <input type="text" name="field3"/>
    <input type="submit" value="submit"/>
</form>

I suggested that fields disabled by the html attribute "disabled" should not be passed to GET.

So, I made js (based on jquery) to disable empty fields in submit, something like this:

$("form").submit(function() {
    $(this).find("input[type=text]").each( function () {
        if (!$.trim($(this).val())) {
            $(this).attr("disabled", "true");
        }
    });
});

However, this does not work. Any ideas?

+3
source share
2 answers

You can remove the attribute nameas follows:

 $("form").submit(function() {
     $(this).find("input[type=text]").each( function () {

        if (!$.trim($(this).val())) {
            $(this).removeAttr("name");
        }
     });
 });

From the W3C Recommendation :

, , . , /, .

+2

disabled : disabled. true.

( disabled - , true, false)

+3

Source: https://habr.com/ru/post/1740280/


All Articles