Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit POST and GET variables in one form

Tags:

html

post

php

get

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.

like image 269
SemperFly Avatar asked Aug 02 '11 21:08

SemperFly


People also ask

Can we use get and POST together?

The question is, can you use GET and POST method together to create different dynamic pages from a single script? The answer is yes!

How use GET and POST method at the same time?

You can't GET and POST at the same time, they're two different HTTP methods. You're either making a GET request or a POST request to a URL. If you need to scrape data from an external data source, then that's a GET.

What is the difference between the $_ GET [] and $_ POST [] Superglobals?

These are superglobals, which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. 3) $_GET is an array of variables passed to the current script via the URL parameters.


1 Answers

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>
like image 188
Flambino Avatar answered Sep 19 '22 18:09

Flambino