Detriamelia.Com – Running form functions in PHP is not difficult. By using the $ _POST and $ _GET methods it becomes easier. Handling forms in PHP with this modern style requires a little knowledge of $ _GET and $ _POST. For that, don’t forget to first learn the concept of handling forms in PHP using these methods. The PHP superglobals $_GET and $_POST are used to collect form-data.
PHP – A Simple HTML Form
The model beneath shows a basic HTML structure with two info fields and a submit button:
1 2 3 4 5 6 7 8 9 |
<html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html> |
At the point when the client rounds out the structure above and taps the submit button, the structure information is sent for preparing to a PHP document named “welcome.php”. The structure information is sent with the HTTP POST strategy.
To show the submitted information you could essentially reverberate all the factors. The “welcome.php” resembles this:
1 2 3 4 5 6 |
<html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> </body> </html> |
The output could be something like this:
1 2 |
Welcome John Your email address is john.doe@example.com |
The same result could also be achieved using the HTTP GET method:
1 2 3 4 5 6 7 8 9 |
<html> <body> <form action="welcome_get.php" method="get"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html> |
and “welcome_get.php” looks like this:
1 2 3 4 5 6 |
<html> <body> Welcome <?php echo $_GET["name"]; ?><br> Your email address is: <?php echo $_GET["email"]; ?> </body> </html> |
The code above is very straightforward. Notwithstanding, the most significant thing is absent. You have to approve structure information to shield your content from malignant code.
Think SECURITY when preparing PHP structures!
This page doesn’t contain any structure approval, it just shows how you can send and recover structure information. In any case, the following pages will tell the best way to process PHP structures in view of security! Legitimate approval of structure information is imperative to shield your structure from programmers and spammers!
$_GET vs $_POST
Both GET and POST make an exhibit (for example exhibit( key1 => value1, key2 => value2, key3 => value3, …)). This exhibit holds key/esteem sets, where keys are the names of the structure controls and qualities are the info information from the client.
Both GET and POST are treated as $_GET and $_POST. These are superglobals, which implies that they are constantly available, paying little heed to scope – and you can get to them from any capacity, class or record without doing anything exceptional.
$_GET is a variety of factors went to the present content by means of the URL parameters.
$_POST is a variety of factors went to the present content by means of the HTTP POST technique.
When to utilize GET?
Data sent from a structure with the GET strategy is noticeable to everybody (every single variable name and qualities are shown in the URL). GET additionally has confines on the measure of data to send. The impediment is around 2000 characters. Be that as it may, in light of the fact that the factors are shown in the URL, it is conceivable to bookmark the page. This can be valuable at times.
GET might be utilized for sending non-delicate information.
Note: GET ought to NEVER be utilized for sending passwords or other delicate data!
When to utilize POST?
Data sent from a structure with the POST strategy is imperceptible to other people (all names/values are inserted inside the body of the HTTP demand) and has no restrictions on the measure of data to send.
In addition POST underpins propelled usefulness, for example, support for multi-part parallel information while transferring documents to server.
Notwithstanding, in light of the fact that the factors are not shown in the URL, it is beyond the realm of imagination to bookmark the page.