I know it's a stupid question, but if I fill a form with various inputs but I don't give them a name and id, and I POST it to a php page, does the posted query contain any data?
If it does, then using inputs without names in a form result in a wasted sending time. am I right?
Is there any difference between GET and POST in this case?
I presume that the browser (client-side) determines what to send and what to not send.
I'll try to see what happens if i send a GET request: if in the browser bar appear something, some data has been sent.
But the POST method is still a mistery for me... when I have time I'll try to print the $_POST array. thanks for the "input" #MattP
I update my question after somebody attack: I printed down the result of $_POST and $_GET, but still, I think the only answer to my question is to check the weight of the data, not the things recognized by the server. If i send unnamed data to the server, the server may discard that ad take only the ones with the name.
(sorry for the bad english)
No, they won't get the data. id is optional, but for PHP to do anything it requires the name attribute.
Related
I read on SoloLearn that the method attribute of an input tag within a form can be set to GET or POST. If both methods are sending data to another location, is an HTTP GET being used somehow? I thought GET was used to retrieve data, not send it. Can anyone help me understand, please?
All HTTP requests involve sending something to the server.
A GET request is designed to be used to ask for something.
If you GET http://example.com/ then you ask for the root document for that site.
If you submit the form at https://duckduckgo.com/ then your request is to GET https://duckduckgo.com/?q=example&t=hf&ia=web. You are asking for the search results for the keyword "example".
Why if I submit an URL like:
localhost:38245/TeamWork/Group/1/LONG-COMMENT-POSTED-BY-USER ,
I get an error that says "Bad Request - invalid URL HTTP Error 400. The request URL is invalid." ?
The default maximum length of a URL is 4096 in IIS. You may well be breaching that with the comment posted by the user. Generally, the best way to transfer that kind of data is by POST rather than in a URL. You can either trim the comment to a more suitable size of increase the maxUrl value in the requestLimits section of your IIS config: http://msdn.microsoft.com/en-us/library/ms689462%28v=vs.90%29.aspx
Firstly, HTTP 400 error is intended for cases when the client has made an error. As you've noticed yourself it's a bad request error. So that means possibly due to bad syntax the request can not be carried out. As Mike Brind mentions, you're most probably exceeding the maximum length of the URL (the default value anyway)
Secondly, why are you trying to "submit" a long post by URL? Use the POST method instead. A way to do this is by using Jquery's Post method to do this. See this. Or simply by calling the form's submit method through OnClick method or however the user is submitting the form.
POST is perfect for transmitting large amounts of data. So submitting data from the client side, the easiest way by far is to use POST to archieve this.
As you have yourself stated in the Question code part,
localhost:38245/TeamWork/Group/1/LONG-COMMENT-POSTED-BY-USER
the Long comment by user, must be inside the limits that are in the web.config file of your website.
Secondly, no Server would allow a very Long Url thinking that the user might be trying to post a malware. Also, using short URLs is good for Data transfer as they consume less data.
From the limits on Requests one would easily come to understand that the URL must be less than 4096bytes, only 4KB. So do you think, all that URL would be 4KB?
As Mike has suggested to use POST request to send the long data, I would also suggest you to use HttpPost requests to send this type of long data. This way, Browser would encrypt the data and sending it as an attachment to the request.
I have an ExpressionEngine site that I'm building with Bootstrap. It's a site for volunteers to find projects to help with. On the home page I have a modal with a form for them to select when they're available and what categories of jobs they're looking for. Then they can click submit and it'll go to a new page with filtered entries.
I don't know if this is possible using the GET method or POST method on the form. I've figured out how to use the GET method and get a query string into my URL but I don't know how to use that data to filter my entries on the entries page. Or would using POST and JSON be a better option? I don't know really how to implement either so any help would be great.
Thanks a lot!
It depends on how the information you would like to show is stored.
If you are using MySQL (a common RDMS), or any other form of SQL Database for that matter, the most common way is to send your GET query string (for example) to your server, have a sever-side language (such as PHP) handle that request by accessing your database, and then echo the result. This can be done synchronously, or with AJAX.
For example, the flow of everything might look like this:
User selects an option (say, "Gardening Projects").
JavaScript converts the value of that input option to a query string and sends an HTTP request using the GET method.
The destination of this request is "filter.php" (for example).
"filter.php" access your database using an SQL query, which searches for any entries in your database, say, having a tag of "gardening".
"filter.php" echos a statement with those entries (or, better yet, returns a JSON object)
JavaScript then parses the resultant JSON object into the DOM, which displays as a bunch of links in a result area that your user can click on.
The question you have about how to handle this is very broad, so I would recommend simply doing some Google searches or looking around this site for resources that show you how to set up databases, access those databases with possibly PHP/SQL, and maybe even use AJAX to return those results, etc.
To get you started (these are in no particular order):
AJAX Tutorial
PHP - JSON encode
SQL tutorial
jQuery AJAX
I got it figured out with some help from #JoshBeam. It turns out that I was trying to make it way more complicated than it actually is. Rookie mistake. In the end I just ended up using method=get in my form and the setting the action as the page with the filtered entries. I then used php to echo the inputs into my EE channel:entries tag.
One thing I still haven't figured out is how to make it so that my query string will combine values for matching names. Currently I have checkboxes for days of the week, each with name="day" and different values for each day. If there are multiple checked, my query string becomes example.com/?day=sun&day=mon when I'd rather have it as example.com/?day=sun&mon. So if anyone has any tips on that, I'd welcome them! I also wonder if there's a way to add pipes between each value when I echo them in my EE tag so that I can have multiples - e.g. {exp:channel:entries category="1|2|3"}. But I have really yet to Google either of these questions so I'll do that.
Thanks!
This question already has answers here:
When should I use GET or POST method? What's the difference between them?
(15 answers)
Closed 9 years ago.
I'm new in this forum and I'm learning PHP from this night.
I want to send a form but I do not know the difference between:
<form action="page2.php" method="GET">
and
<form action="page2.php" method="POST">
Anyone could help me please ?
Thanks.
GET:
Parameters remain in browser history because they are part of the URL
Can be bookmarked.
GET method should not be used when sending passwords or other sensitive information.
7607 character maximum size.
Url example: page2.php?category=sport
POST:
Parameters are not saved in browser history.
Can not be bookmarked.
POST method used when sending passwords or other sensitive information.
8 Mb max size for the POST method.
Url example: page2.php
By convention HTTP GET is used for search forms while HTTP POST is used to change forms. A GET displays its information in the URL, publicly viewable, from which you can query the variables. A POST will not display its information. There is really no difference security wise.
If a GET request is used, the form parameters are encoded in the URL in what is called a query string.For example
www.someemailprovider.com/?login=joe#email.com&password=xxyz
A POST request, unlike a GET request, passes the form parameters in the body of the HTTP request, not in the URL.
Moreover GET is idempotent and POST is not that means If you call GET method on server nothing will be changed on server, but if you call POST then server will be changed may be a some additional data will be added in to the server, so GET is idempotent while POST is not.
Note
The main thing to keep in mind as a programmer is that defining your form to use the GET method does not protect against causing changes. You could use a GET request to do pretty much the same thing as a POST query. It’s just that browsers are generally coded to expect that POST requests will be used for things that will cause changes – like placing an order, or writing to a database, etc . GET requests should be used for pure queries that don’t affect anything on the server. So, one should always remember not to use GET requests for any action that would cause a change on the server – like ordering a big screen tv.
These are both HTTP request methods, not PHP exclusive.
$_GET is appended to end or URL. i.e. http://example.org/?foo=bar
Access it in PHP with:
$foo = $_GET['foo'];
or
$foo = $_REQUEST['foo'];
GET is used for information you don't mind people seeing, and can be manually typed into links and urls to get results.
$_POST is not visible in your URL, and generally is used after submitting a form.
Access it in PHP with:
$foo = $_POST['foo'];
or
$foo = $_REQUEST['foo'];
Read more about HTTP requests at http://www.w3schools.com/tags/ref_httpmethods.asp
Can any one please explain me action attribute do take local disk file and work with get and post method to send and retrieve data back. I want explanation and example both.
Please and thanks for help
Try reading a little bit more about HTML forms and make some tutorials, action is sort of the "link" you are going to send the information of the form to. That "link" can then ask for the information that has been passed to it through the form fields.
Searching in google returned quite a few nice places to start with:
http://www.w3schools.com/html/html_forms.asp
http://www.tizag.com/htmlT/forms.php/
The first link I gave says:
The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input
and the second one says:
HTML form elements rely on action and method attributes to identify where to send the form data for processing (action) and how to process the data (method)
That is a good point of start. Give them a try, read some more and if you are still having trouble, come back for some more help.