简体   繁体   中英

Hide submit type input value from url

I have a form with GET method with some inputs like this:

<input type="text" name="something">
<input type="submit" name="submit" value="Click here to submit form">

I don't want the url to become

mypage.php?something=value&submit=Click+here+to+submit+form 

I want to suppress the submit parameter in the url (should be like this: mypage.php?something=value).

I need only GET method please don't mention POST method. Also you may mention to remove name="submit" but i need it also to identify this submit.

Also if there is a input from which is empty i don't want to show

<input type="text" name="input1">
<input type="text" name="input2">
<input type="submit" name="submit" value="Click here to submit form">

input1 gets value but if input2 doesn't have value the i want url like mypage.php?input1=value

Thanks

如果您不希望submit参数显示在GET请求URL中,请不要给它起一个名字,而是使用idclass唯一地标识它:

<input type="submit" id="submit" value="Click here to submit form">

I would remove form submit the and just turn it into a button. Then I would use jquery to submit the form and do any logic processing.

<input type="test" id="favoriteCheese" value="nacho" />
<button id="submit" value="Click here to submit form">Click here to submit form</button>

$("#submit").on('click', function () {
    var data = {};
    var favCheese = $("#favCheese").val();
    if(favCheese.length > 0) {
        data.favCheese = favCheese
    }
    $.ajax({
        url : ".../mypage.php",
        data : data,
        type : 'GET',
        ...
    })
})

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