All welcome.

There is a form:

<form action="example.php" method="GET"> <input type="text" name="example"> <input type="submit" value="test"> <select name="selector"> <option value="0">Селектор</option> <option value="1">1</option> <option value="2">2</option> </select> </form> 

As the GET request goes, all the name arguments go to the URL. (example.php? example = test & selector = 1)

How can you make the data passed to the file example.php, but so that the selector does not go to the URL?

Thank you in advance.

  • Dicky friend suffer. - Andrey Arshinov

3 answers 3

As always, there are 2 options for implementation.

I describe the first: Before sending the form using the GET method, we make the selector field closed ie. disabled.

 $('form').submit(function(){ $('form select[name=selector]').prop('disabled', true); return true; }); 

if the code does not work this way (it will not have time to close the Select before sending), then we do this:

 $('form input:submit').click(function(){ e.preventDefault(); $('form select[name=selector]').prop('disabled', true); $('form').submit(); return true; }); 

And the second way is to process the GET request on the server side using the PHP method. For example, like this:

 //удаляем не нужный параметр if(isset($_GET['selector'])) { unset($_GET['selector']); // получаем строку вида key=val&key1=val1&key2=val2 $clean_url = http_build_query($_GET); // остается сделать редирект любым удобным способом header('Location... } 

    method = "post"

    • @mountpoint, unfortunately, I need exactly the GET method. - evansive
    • post from get exactly the same. You can of course transfer the data with the js in the custom header ... - zb '
    • @evansive, why is the post not suitable? - mountpoint
    • eight
      What, what, sorry? I want the selector not to be displayed, but the POST method does not suit me? In the Same Series: - I want to create objects, but object-oriented languages ​​are not suitable. - I want to create a site, but programming is not suitable. - I want to cook scrambled eggs, but eggs do not fit. - just
    • gold words. catch the plus - mountpoint

    Hmm, if I do not confuse anything, then you can save it in js via cookies, and pick up these cookies from php.?

    • one
      I also thought of writing this, but then I was ashamed of my crazy idea :) - dekameron