GET 방식 폼 데이터 전송 GET method data form transmission

-아래의 이미지에서 볼 수 있는 것처럼 GET방식 폼데이터 전송은 브라우저의 주소표시줄을 통해서 데이터를 전송하는 것을 의미합니다.
-아래의 링크를 통해서 테스트 할 수 있습니다
As you can see in the image below, GET form data transmission means sending data through the browser’s address bar.
You can test it through the link below.

https://freelifemakers.org/lec/form2.php


form2.php와 form_action2.php파일은 기존의 form1.php파일과 form2.php파일을 수정한 파일 입니다.
아래의 전체 코드에서 그린 컬러는 변경된 코드 내용이고 오렌지 컬러는 새로 추가된 코드 입니다.
The form2.php and form_action2.php files are modified files from the existing form1.php and form2.php files.
In the entire code below, the green color is the changed code content and the orange color is the newly added code.


1.form2.php
이해하기 쉽도록 하기 위해서 php코드에서 html코드로 수정했습니다.
여기서 데이터 전송 방식으로 form method=”post”에서 form method=”get”으로 변경했습니다.
To make it easier to understand, I modified the PHP code to HTML code.
Here, the data transmission method was changed from form method=”post” to form method=”get”.

<form action="./form_action2.php" method="get">
form2.php

<!DOCTYPE html>
<html>
    <head>
      <title>Bootstrap 5 Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <form action="./form_action2.php" method="get">
        <div class="mb-3 mt-3">
            <label for="name" class="form-label">이름(Name):</label>
            <input type="name" class="form-control" id="name" placeholder="당신의 이름을 입력하세요(Enter Your Name)" name="name">
        </div>
        <div class="mb-3">
            <label for="pwd" class="form-label">Password:</label>
            <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pswd">
        </div>
            <div class="form-check mb-3">
            <label class="form-check-label">
            <input class="form-check-input" type="checkbox" name="remember"> Remember me
            </label>
        </div>
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
    </body>
</html>    

2.form_action2.php
– 데이터의 GET방식 전송이 맞는지 확인 하기 위해서 $_SERVER[‘REQUEST_METHOD 를 POST에서 “GET”으로 변경했습니다.
– $_SERVER[‘REQUEST_METHOD의 값 값을 확인 하기 위해서 다음과 같은 코드를 추가했습니다.
To check whether the GET method of data transmission is correct, $_SERVER[‘REQUEST_METHOD was changed from POST to “GET”.
I added the following code to check the value of $_SERVER[‘REQUEST_METHOD.

form_action2.php

<?php  
if($_SERVER['REQUEST_METHOD'] == "GET"){

   $f_name = $_GET['name'];
   $f_pwd = $_GET['pswd'];
}
echo "REQUEST_METHOD:".$_SERVER['REQUEST_METHOD']."<br>";
echo $f_name."<br>";
echo $f_pwd;
?>

Leave a Reply

Your email address will not be published. Required fields are marked *