Rumah  >  Artikel  >  php教程  >  PHP 对 GET 和 POST 的表单提交方式处理

PHP 对 GET 和 POST 的表单提交方式处理

PHP中文网
PHP中文网asal
2016-05-25 17:16:02990semak imbas

<html>
</head>
<body>
    <?php
      if ($_GET[&#39;submitted&#39;] == "yes"){
        if (trim ($_GET[&#39;yourname&#39;]) != ""){
          echo "Your Name (with GET): " . $_GET[&#39;yourname&#39;];
        } else {
          echo "You must submit a value.";
        }
        ?><br /><a href="index.php">Try Again</a><?php
      }
      if ($_POST[&#39;submitted&#39;] == "yes"){
        if (trim ($_POST[&#39;yourname&#39;]) != ""){
          echo "Your Name (with POST): " . $_POST[&#39;yourname&#39;];
        } else {
          echo "You must submit a value.";
        }
        ?><br /><a href="index.php">Try Again</a><?php
      }
    ?>
    <?php
      if ($_GET[&#39;submitted&#39;] != "yes" && $_POST[&#39;submitted&#39;] != "yes"){
        ?>
        <form action="index.php" method="get">
          <p>GET Example:</p>
          <input type="hidden" name="submitted" value="yes" />
          Your Name: <input type="text" name="yourname" maxlength="150" /><br />
          <input type="submit" value="Submit with GET"/>
        </form>
        <form action="index.php" method="post">
          <p>POST Example:</p>
          <input type="hidden" name="submitted" value="yes" />
          Your Name: <input type="text" name="yourname" maxlength="150" /><br />
          <input type="submit" value="Submit with POST"/>
        </form>
        <?php
      }
    ?>
</body>
</html>


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn