首页  >  文章  >  php教程  >  PHP 对 GET 和 POST 的表单提交方式处理

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

PHP中文网
PHP中文网原创
2016-05-25 17:16:02990浏览

<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>


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn