Submit POST and GET variables in one form

2019-01-26 13:38发布

I'm working on a query tool that displays data from a MySQL database. The user is presented with a form containing a few dozen dynamically-generated checkboxes so that they can select how to view the data. This data is submitted as a GET request and is (obviously) displayed in the url when the requested page loads.

On the same page as the input form, I have a php array that I am generating dynamically and that needs to be sent to the same place as the GET request. However, I do not want the values in this array to be displayed in the URL (i'm using them internally) so I'd like to submit them as a POST request instead.

Obviously, I can't do both a GET and POST request at the same time. I'm new to web development (computer science guy, otherwise) and have been scratching my head on how to approach this.

Let me know if the problem isn't clear.

EDIT: Many have suggested I add them to the action variable a la:

form action="process.php?get1=value...

All of these inputs are generated dynamically so to put them in the action variable is not feasible.

标签: php html post get
5条回答
Viruses.
2楼-- · 2019-01-26 13:52

You can set GET vars by changing URL:

<form action="foo.php?getvar=15" method="POST">
<input name="postvar">
</form>

For dynamic GET vars I believe you need Javascript.

查看更多
男人必须洒脱
3楼-- · 2019-01-26 13:53
<form action="page.php?id=15" method="POST">
<input name="ref_code_cust" type="text" value="some data">
<input name="send" type="submit" value="send">
</form>

or

www.mywebsite/page.php?id=15

<form action="page.php" method="POST">
<input name="id" type="hidden" value="<?php echo htmlspecialchars($_GET['id'], ENT_QUOTES); ?>"> 
<input name="email" type="text" value="some data">
<input name="send" type="submit" value="send">
</form>

we need to see your code also to make it easier, especial this array thing

查看更多
Bombasti
4楼-- · 2019-01-26 13:54

Endophage:

If it's a PHP array, just store it in a session.

This worked great. Obviously, I'm showing my web development greenness here as I didn't really consider using a session.

查看更多
贪生不怕死
5楼-- · 2019-01-26 14:02

You cannot do a post and a get in the same form you even said that in your question.

You have to either:

  1. Have 2 forms
  2. Have one thing submit with a post via ajax and then submit the other form with a get
查看更多
家丑人穷心不美
6楼-- · 2019-01-26 14:10

GET parameters go in the action url, POST parameters in the form's inputs

<form method="post" action="/somepage.php?get=parameters&are=here">
    <input type="text" name="postParameter" value="this value will be sent as POST">
    ... etc
</form>
查看更多
登录 后发表回答