submitting a GET form with query string params and hidden params disappear

前端 未结 10 667
庸人自扰
庸人自扰 2020-11-22 02:22

Consider this form:

相关标签:
10条回答
  • 2020-11-22 03:19
    <form ... action="http:/www.blabla.com?a=1&b=2" method ="POST">
    <input type="hidden" name="c" value="3" /> 
    </form>
    

    change the request method to' POST' instead of 'GET'.

    0 讨论(0)
  • 2020-11-22 03:21

    I usually write something like this:

    foreach($_GET as $key=>$content){
            echo "<input type='hidden' name='$key' value='$content'/>";
    }
    

    This is working, but don't forget to sanitize your inputs against XSS attacks!

    0 讨论(0)
  • 2020-11-22 03:24

    What you can do is using a simple foreach on the table containing the GET information. For example in php :

    foreach ($_GET as $key => $value) {
        echo("<input type='hidden' name='$key' value='$value'/>");
    }
    
    0 讨论(0)
  • 2020-11-22 03:25

    This is in response to the above post by Efx:

    If the URL already contains the var you want to change, then it is added yet again as a hidden field.

    Here is a modification of that code as to prevent duplicating vars in the URL:

    foreach ($_GET as $key => $value) {
        if ($key != "my_key") {
            echo("<input type='hidden' name='$key' value='$value'/>");
        }
    }
    
    0 讨论(0)
提交回复
热议问题