Quantcast
Channel: Excel Management Web Wonders
Viewing all articles
Browse latest Browse all 11

GETing data

$
0
0

Hi Everyone!

 

As I’m sure you all know, requests are the fundamentals of the web, so knowing how to handle them are a must. Today we’re going to be handling form submissions using the GET method. For those of you who don’t know, HTTP (Hyper Text Transfer Protocol) has two primary methods for handling a request/response, GET and POST.

 

The main differences between the two are that GET method sends data to the URL

(/example/process.php?name=Excel+Management),
  where as the POST method is sending it’s data inside the HTTP request body.

 

To illustrate how a GET request can be used, we’re going to start off by making a simple HTML form that allows users to enter in their name and email address:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <form action="process.php" method="GET">
            <input type="text" placeholder="Full Name" name="name" required></input>
            <input type="email" placeholder="Email Address" name="email" required></input>
            <button type="submit">Process me!</button>

    </form>
</body>
</html>

 

HTML 5 Note: By sticking the 

required
 inside the inputs, we add HTML 5 Validation.

 

Next, we’re going to create a file to process the GET request, we’re going to be using

$_GET["nameOfElement"]
 to get the name. Your 
process.php
 should look something like this:
<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <title></title>
</head>
<body>
        Your name is:<b> <?php echo $_GET["name"]; ?></b>
<br>
        Your Email Address is:<b> <?php echo $_GET["email"]; ?></b>
</body>

</html>

PHP Syntax Note: While we can technically use a shorter 

<?=
 tag to echo some PHP, using the conventional
<?php echo...?>
  is considered best practice, and is encouraged.

 

Now, when we press the submit button, we’re going to be redirected to the  

process.php
 page, where the PHP will get the values of the “name” and “email” fields from the URL, and echo them.

Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images