php - Only pass GET information if isset -
I am using a form with GET method to add to the query string.
I am running an issue. When a form is presented, each field is sent and added to the query, with any value.
Example:
http://web.com/?filter-types=News and Filters -Document-Type = & amp; Filter-Subjects = We-are-one-topic & amp; Filter-featured = & amp; Filter-Rating =
Can I not add these query strings if they are not set? ! Isset ()
or another way to do this?
You can optionally manipulate the input via javascript, just a mic comment In the said Submit Submit field, if empty, disable them so that they are not included in the submission.
This is just the basic idea (with jQuery):
& lt; Form method = "GET" id = "form_inputs" & gt; & Lt; Input type = "text" name = "field1" value = "field_w_main" gt gt; & Lt; Br / & gt; & Lt; Input type = "text" name = "field2" value = "" /> gt; & Lt; Br / & gt; & Lt ;! - Empty field - & gt; & Lt; Input type = "text" name = "field3" value = "field_w_mount" gt gt; & Lt; Br / & gt; & Lt; Input type = "submit" name = "submit_form" id = "submit_form" value = "submit" /> & Lt; / Form & gt; & Lt; Script src = "// ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> & Lt; Script type = "text / javascript" & gt; $ ('Input [name = "submit_form"]'). ('Click', function (e) {e.preventDefault (); $ ('form'). Children () (function (i, e) {If ($ (e) .is ('input') & Amp; $ (this) .val () == '') {$ (this) .prop ('disabled', true); // or $ (this) .attr ('name', '');}} ); $ ('Form'). Submit ();}); & Lt; / Script & gt;
Or if you do not want to use jquery at all:
document.getElementById ('submit_form'). AddEventListener ('click', function e) {E.Pravant Default (); Var kids = document.getElementById ('form_inputs'). (I = 0; i & lt; children.length; i ++) {if (children [i] .type == 'text' & children [i] .value == '') {children [ I] .disabled = true;}} document.getElementById ('form_inputs'). Submit ();});
Comments
Post a Comment