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

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

PHP中文网
PHP中文网원래의
2016-05-25 17:16:02988검색

<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으로 문의하세요.