Home > php教程 > PHP源码 > PHP 对 GET 和 POST 的表单提交方式处理

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

PHP中文网
Release: 2016-05-25 17:16:02
Original
1099 people have browsed it

<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>
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template