Reputation:
There is an html table in my page with 3 columns, each one of them contains a form like this
<form id="filter" method="get" action="advanced_search_result.php">
<input type="hidden" value="Aurum" name="keywords">
<select onchange="this.form.submit()" name="maxnumber">
<option value="">10</option>
<option selected="selected" value="25">25</option>
<option value="50">50</option>
</select>
</form>
the outcome of a dropdown selection is the page to reload with a url like this "advanced_search_result.php?keywords=Aurum&maxnumber=25", and my question is....how do these querystring parameters get constructed? I have looked through the php file and cannot figure it out. What I want to do is add another parameter to the url when this action occurs.
Upvotes: 1
Views: 120
Reputation: 28511
This is a default behaviour of the HTTP protocol, which has 4 possible actions: GET, PUT, POST, DELETE. It is not the language performing the action.
The best possible explanation about REST and using the HTTP protocol is HERE. This Wikipedia article also holds more information about the different types of requests you can do with HTTP.
Bottom line
It's the protocol that creates the URL in that format. PHP, like all modern web languages, has HTTP wrapper methods that know how to extract parameters from their URL representation, such as the $_GET
array, the $_POST
array or the $_REQUEST
array.
The one thing you should know Idempotence In plain English, this means use the right type of request for an action to allow the browser to do its job in a more efficient way. You don't use POST to simply display database content and you don't use GET to update your database. Why? Read more HERE.
Idempotence explained
Idempotent methods and web applications
Methods PUT and DELETE are defined to be idempotent, meaning that multiple identical requests should have the same effect as a single request (Note that idempotence refers to the state of the system after the request has completed, so while the action the server takes (e.g. deleting a record) or the response code it returns may be different on subsequent requests, the system state will be the same every time).
Methods GET, HEAD, OPTIONS and TRACE, being prescribed as safe, should also be idempotent, as HTTP is a stateless protocol.1 In contrast, the POST method is not necessarily idempotent, and therefore sending an identical POST request multiple times may further affect state or cause further side effects (such as financial transactions).
In some cases this may be desirable, but in other cases this could be due to an accident, such as when a user does not realize that their action will result in sending another request, or they did not receive adequate feedback that their first request was successful. While web browsers may show alert dialog boxes to warn users in some cases where reloading a page may re-submit a POST request, it is generally up to the web application to handle cases where a POST request should not be submitted more than once.
Note that whether a method is idempotent is not enforced by the protocol or web server. It is perfectly possible to write a web application in which (for example) a database insert or other non-idempotent action is triggered by a GET or other request. Ignoring this recommendation, however, may result in undesirable consequences, if a user agent assumes that repeating the same request is safe when it isn't.
Upvotes: 2
Reputation: 643
As others have said, the construction of the GET
paramenters has nothing to do with PHP.
Aside from that, if you want to add a new paramenter, simply add a new input to the form:
<input type="text" name="param_name" value="the_value" />
Upvotes: 0
Reputation: 360762
That has absolutely nothing to do with php. you're using a get
method on the form, so all the form field names/values are stuffed into the url as query parameters.
This would happen if the page was built with java, asp, ruby, perl, or even plain-old static html.
Upvotes: 3